From 945fa72dc088cbedc956f44b1f1ec69f35e90064 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Sat, 17 Nov 2007 20:50:00 +0100 Subject: [PATCH] logfile plugin: Default to $localstatedir/log/collectd.log instead of STDOUT. Imho STDOUT is only a useful default during debugging (which should be by far the less common case ;-). In any other case it might just "pollute" the messages printed by e.g. the init script. Signed-off-by: Sebastian Harl Signed-off-by: Florian Forster --- src/logfile.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/logfile.c b/src/logfile.c index 03c2f923..f4661245 100644 --- a/src/logfile.c +++ b/src/logfile.c @@ -26,6 +26,8 @@ #include +#define DEFAULT_LOGFILE LOCALSTATEDIR"/log/collectd.log" + #if COLLECT_DEBUG static int log_level = LOG_DEBUG; #else @@ -107,7 +109,12 @@ static void logfile_log (int severity, const char *msg) pthread_mutex_lock (&file_lock); - if ((log_file == NULL) || (strcasecmp (log_file, "stderr") == 0)) + if (log_file == NULL) + { + fh = fopen (DEFAULT_LOGFILE, "a"); + do_close = 1; + } + else if (strcasecmp (log_file, "stderr") == 0) fh = stderr; else if (strcasecmp (log_file, "stdout") == 0) fh = stdout; @@ -121,7 +128,7 @@ static void logfile_log (int severity, const char *msg) { char errbuf[1024]; fprintf (stderr, "logfile plugin: fopen (%s) failed: %s\n", - (log_file == NULL) ? "" : log_file, + (log_file == NULL) ? DEFAULT_LOGFILE : log_file, sstrerror (errno, errbuf, sizeof (errbuf))); } else -- 2.30.2