[collectd] [PATCH] logfile plugin: Default to $localstatedir/log/collectd.log instead of STDOUT.

Sebastian Harl sh at tokkee.org
Sat Nov 17 20:50:00 CET 2007


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 <sh at tokkee.org>
---
 src/logfile.c |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/logfile.c b/src/logfile.c
index 03c2f92..f466124 100644
--- a/src/logfile.c
+++ b/src/logfile.c
@@ -26,6 +26,8 @@
 
 #include <pthread.h>
 
+#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) ? "<null>" : log_file,
+					(log_file == NULL) ? DEFAULT_LOGFILE : log_file,
 					sstrerror (errno, errbuf, sizeof (errbuf)));
 	}
 	else
-- 
1.5.3.4

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mailman.verplant.org/pipermail/collectd/attachments/20071117/f7cd5987/attachment.pgp 


More information about the collectd mailing list