diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-11-23 08:47:51 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-11-23 08:47:51 +0000 |
commit | 276363680b531de5b289401fa75e04149061c029 (patch) | |
tree | 4553bc5801b1a7692ee52cbc114cfb89d11d0d90 /src/util/common_logging.c | |
parent | 8630d77ce5d9e37932197bca16c9edef98fbaf8b (diff) | |
download | gnunet-276363680b531de5b289401fa75e04149061c029.tar.gz gnunet-276363680b531de5b289401fa75e04149061c029.zip |
preparations for fixing #4065
Diffstat (limited to 'src/util/common_logging.c')
-rw-r--r-- | src/util/common_logging.c | 57 |
1 files changed, 42 insertions, 15 deletions
diff --git a/src/util/common_logging.c b/src/util/common_logging.c index f5688f42c..101347bfb 100644 --- a/src/util/common_logging.c +++ b/src/util/common_logging.c | |||
@@ -149,7 +149,7 @@ static struct CustomLogger *loggers; | |||
149 | /** | 149 | /** |
150 | * Number of log calls to ignore. | 150 | * Number of log calls to ignore. |
151 | */ | 151 | */ |
152 | int skip_log = 0; | 152 | static int skip_log = 0; |
153 | 153 | ||
154 | /** | 154 | /** |
155 | * File descriptor to use for "stderr", or NULL for none. | 155 | * File descriptor to use for "stderr", or NULL for none. |
@@ -342,10 +342,15 @@ setup_log_file (const struct tm *tm) | |||
342 | if ( (NULL != leftsquare) && (']' == leftsquare[1]) ) | 342 | if ( (NULL != leftsquare) && (']' == leftsquare[1]) ) |
343 | { | 343 | { |
344 | char *logfile_copy = GNUNET_strdup (fn); | 344 | char *logfile_copy = GNUNET_strdup (fn); |
345 | |||
345 | logfile_copy[leftsquare - fn] = '\0'; | 346 | logfile_copy[leftsquare - fn] = '\0'; |
346 | logfile_copy[leftsquare - fn + 1] = '\0'; | 347 | logfile_copy[leftsquare - fn + 1] = '\0'; |
347 | snprintf (fn, PATH_MAX, "%s%d%s", | 348 | snprintf (fn, |
348 | logfile_copy, getpid (), &logfile_copy[leftsquare - fn + 2]); | 349 | PATH_MAX, |
350 | "%s%d%s", | ||
351 | logfile_copy, | ||
352 | getpid (), | ||
353 | &logfile_copy[leftsquare - fn + 2]); | ||
349 | GNUNET_free (logfile_copy); | 354 | GNUNET_free (logfile_copy); |
350 | } | 355 | } |
351 | if (0 == strcmp (fn, last_fn)) | 356 | if (0 == strcmp (fn, last_fn)) |
@@ -405,8 +410,13 @@ setup_log_file (const struct tm *tm) | |||
405 | * @return 0 on success, regex-specific error otherwise | 410 | * @return 0 on success, regex-specific error otherwise |
406 | */ | 411 | */ |
407 | static int | 412 | static int |
408 | add_definition (char *component, char *file, char *function, int from_line, | 413 | add_definition (const char *component, |
409 | int to_line, int level, int force) | 414 | const char *file, |
415 | const char *function, | ||
416 | int from_line, | ||
417 | int to_line, | ||
418 | int level, | ||
419 | int force) | ||
410 | { | 420 | { |
411 | struct LogDef n; | 421 | struct LogDef n; |
412 | int r; | 422 | int r; |
@@ -461,8 +471,11 @@ add_definition (char *component, char *file, char *function, int from_line, | |||
461 | * @return 0 to disallow the call, 1 to allow it | 471 | * @return 0 to disallow the call, 1 to allow it |
462 | */ | 472 | */ |
463 | int | 473 | int |
464 | GNUNET_get_log_call_status (int caller_level, const char *comp, | 474 | GNUNET_get_log_call_status (int caller_level, |
465 | const char *file, const char *function, int line) | 475 | const char *comp, |
476 | const char *file, | ||
477 | const char *function, | ||
478 | int line) | ||
466 | { | 479 | { |
467 | struct LogDef *ld; | 480 | struct LogDef *ld; |
468 | int i; | 481 | int i; |
@@ -696,13 +709,17 @@ GNUNET_log_setup (const char *comp, | |||
696 | 709 | ||
697 | 710 | ||
698 | /** | 711 | /** |
699 | * Add a custom logger. | 712 | * Add a custom logger. Note that installing any custom logger |
713 | * will disable the standard logger. When multiple custom loggers | ||
714 | * are installed, all will be called. The standard logger will | ||
715 | * only be used if no custom loggers are present. | ||
700 | * | 716 | * |
701 | * @param logger log function | 717 | * @param logger log function |
702 | * @param logger_cls closure for @a logger | 718 | * @param logger_cls closure for @a logger |
703 | */ | 719 | */ |
704 | void | 720 | void |
705 | GNUNET_logger_add (GNUNET_Logger logger, void *logger_cls) | 721 | GNUNET_logger_add (GNUNET_Logger logger, |
722 | void *logger_cls) | ||
706 | { | 723 | { |
707 | struct CustomLogger *entry; | 724 | struct CustomLogger *entry; |
708 | 725 | ||
@@ -721,7 +738,8 @@ GNUNET_logger_add (GNUNET_Logger logger, void *logger_cls) | |||
721 | * @param logger_cls closure for @a logger | 738 | * @param logger_cls closure for @a logger |
722 | */ | 739 | */ |
723 | void | 740 | void |
724 | GNUNET_logger_remove (GNUNET_Logger logger, void *logger_cls) | 741 | GNUNET_logger_remove (GNUNET_Logger logger, |
742 | void *logger_cls) | ||
725 | { | 743 | { |
726 | struct CustomLogger *pos; | 744 | struct CustomLogger *pos; |
727 | struct CustomLogger *prev; | 745 | struct CustomLogger *prev; |
@@ -756,17 +774,26 @@ CRITICAL_SECTION output_message_cs; | |||
756 | * @param msg the actual message | 774 | * @param msg the actual message |
757 | */ | 775 | */ |
758 | static void | 776 | static void |
759 | output_message (enum GNUNET_ErrorType kind, const char *comp, | 777 | output_message (enum GNUNET_ErrorType kind, |
760 | const char *datestr, const char *msg) | 778 | const char *comp, |
779 | const char *datestr, | ||
780 | const char *msg) | ||
761 | { | 781 | { |
762 | struct CustomLogger *pos; | 782 | struct CustomLogger *pos; |
783 | |||
763 | #if WINDOWS | 784 | #if WINDOWS |
764 | EnterCriticalSection (&output_message_cs); | 785 | EnterCriticalSection (&output_message_cs); |
765 | #endif | 786 | #endif |
766 | if (NULL != GNUNET_stderr) | 787 | /* only use the standard logger if no custom loggers are present */ |
788 | if ( (NULL != GNUNET_stderr) && | ||
789 | (NULL == loggers) ) | ||
767 | { | 790 | { |
768 | FPRINTF (GNUNET_stderr, "%s %s %s %s", datestr, comp, | 791 | FPRINTF (GNUNET_stderr, |
769 | GNUNET_error_type_to_string (kind), msg); | 792 | "%s %s %s %s", |
793 | datestr, | ||
794 | comp, | ||
795 | GNUNET_error_type_to_string (kind), | ||
796 | msg); | ||
770 | fflush (GNUNET_stderr); | 797 | fflush (GNUNET_stderr); |
771 | } | 798 | } |
772 | pos = loggers; | 799 | pos = loggers; |