From: Sebastian Harl Date: Sat, 17 Nov 2007 19:50:00 +0000 (+0100) Subject: logfile plugin: Default to $localstatedir/log/collectd.log instead of STDOUT. X-Git-Tag: collectd-4.3.0beta0~82 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=945fa72dc088cbedc956f44b1f1ec69f35e90064;p=collectd.git 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 --- 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