diff options
Diffstat (limited to 'src/lib/util/common_logging.c')
-rw-r--r-- | src/lib/util/common_logging.c | 61 |
1 files changed, 45 insertions, 16 deletions
diff --git a/src/lib/util/common_logging.c b/src/lib/util/common_logging.c index 458802a07..37c6064b8 100644 --- a/src/lib/util/common_logging.c +++ b/src/lib/util/common_logging.c | |||
@@ -771,7 +771,8 @@ GNUNET_log_setup (const char *comp, | |||
771 | 771 | ||
772 | 772 | ||
773 | void | 773 | void |
774 | GNUNET_logger_add (GNUNET_Logger logger, void *logger_cls) | 774 | GNUNET_logger_add (GNUNET_Logger logger, |
775 | void *logger_cls) | ||
775 | { | 776 | { |
776 | struct CustomLogger *entry; | 777 | struct CustomLogger *entry; |
777 | 778 | ||
@@ -784,7 +785,8 @@ GNUNET_logger_add (GNUNET_Logger logger, void *logger_cls) | |||
784 | 785 | ||
785 | 786 | ||
786 | void | 787 | void |
787 | GNUNET_logger_remove (GNUNET_Logger logger, void *logger_cls) | 788 | GNUNET_logger_remove (GNUNET_Logger logger, |
789 | void *logger_cls) | ||
788 | { | 790 | { |
789 | struct CustomLogger *pos; | 791 | struct CustomLogger *pos; |
790 | struct CustomLogger *prev; | 792 | struct CustomLogger *prev; |
@@ -820,8 +822,21 @@ output_message (enum GNUNET_ErrorType kind, | |||
820 | const char *datestr, | 822 | const char *datestr, |
821 | const char *msg) | 823 | const char *msg) |
822 | { | 824 | { |
825 | static int have_journald = -1; | ||
823 | struct CustomLogger *pos; | 826 | struct CustomLogger *pos; |
824 | 827 | ||
828 | if (-1 == have_journald) | ||
829 | { | ||
830 | /* systemd after version 231 sets this environment | ||
831 | variable if we are logging to journald. In this | ||
832 | case, skip outputting our component name, PID | ||
833 | and timestamp as journald already adds those. (#8032) */ | ||
834 | if (NULL != getenv ("JOURNAL_STREAM")) | ||
835 | have_journald = 1; | ||
836 | else | ||
837 | have_journald = 0; | ||
838 | } | ||
839 | |||
825 | /* only use the standard logger if no custom loggers are present */ | 840 | /* only use the standard logger if no custom loggers are present */ |
826 | if ((NULL != GNUNET_stderr) && (NULL == loggers)) | 841 | if ((NULL != GNUNET_stderr) && (NULL == loggers)) |
827 | { | 842 | { |
@@ -834,7 +849,8 @@ output_message (enum GNUNET_ErrorType kind, | |||
834 | * interactively, yet the same message shouldn't look | 849 | * interactively, yet the same message shouldn't look |
835 | * this way if the output is going to logfiles or robots | 850 | * this way if the output is going to logfiles or robots |
836 | * instead. | 851 | * instead. |
837 | */fprintf (GNUNET_stderr, "* %s", msg); | 852 | */ |
853 | fprintf (GNUNET_stderr, "* %s", msg); | ||
838 | } | 854 | } |
839 | else if (GNUNET_YES == current_async_scope.have_scope) | 855 | else if (GNUNET_YES == current_async_scope.have_scope) |
840 | { | 856 | { |
@@ -850,22 +866,35 @@ output_message (enum GNUNET_ErrorType kind, | |||
850 | GNUNET_assert (NULL != end); | 866 | GNUNET_assert (NULL != end); |
851 | *end = '\0'; | 867 | *end = '\0'; |
852 | skip_log = 0; | 868 | skip_log = 0; |
853 | fprintf (GNUNET_stderr, | 869 | if (have_journald) |
854 | "%s %s(%s) %s %s", | 870 | fprintf (GNUNET_stderr, |
855 | datestr, | 871 | "(%s) %s %s", |
856 | comp, | 872 | id_buf, |
857 | id_buf, | 873 | GNUNET_error_type_to_string (kind), |
858 | GNUNET_error_type_to_string (kind), | 874 | msg); |
859 | msg); | 875 | else |
876 | fprintf (GNUNET_stderr, | ||
877 | "%s %s(%s) %s %s", | ||
878 | datestr, | ||
879 | comp, | ||
880 | id_buf, | ||
881 | GNUNET_error_type_to_string (kind), | ||
882 | msg); | ||
860 | } | 883 | } |
861 | else | 884 | else |
862 | { | 885 | { |
863 | fprintf (GNUNET_stderr, | 886 | if (have_journald) |
864 | "%s %s %s %s", | 887 | fprintf (GNUNET_stderr, |
865 | datestr, | 888 | "%s %s", |
866 | comp, | 889 | GNUNET_error_type_to_string (kind), |
867 | GNUNET_error_type_to_string (kind), | 890 | msg); |
868 | msg); | 891 | else |
892 | fprintf (GNUNET_stderr, | ||
893 | "%s %s %s %s", | ||
894 | datestr, | ||
895 | comp, | ||
896 | GNUNET_error_type_to_string (kind), | ||
897 | msg); | ||
869 | } | 898 | } |
870 | fflush (GNUNET_stderr); | 899 | fflush (GNUNET_stderr); |
871 | } | 900 | } |