chiark / gitweb /
logfile: Log to stderr by default (`filename' key now optional)
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 23 Nov 2019 17:50:28 +0000 (17:50 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 30 Dec 2019 13:15:49 +0000 (13:15 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
README
log.c

diff --git a/README b/README
index ce3a4d70b44d4946462bf9f0c62718fd3a41463f..d06a71b814408b522c8c8e6aa798a9cf67fc27e9 100644 (file)
--- a/README
+++ b/README
@@ -315,7 +315,7 @@ Defines:
   syslog (closure => log closure)
 
 logfile: dict argument
-  filename (string): where to log to
+  filename (string): where to log to; default is stderr
   class (string list): what type of messages to log
     { "debug-config", M_DEBUG_CONFIG },
     { "debug-phase", M_DEBUG_PHASE },
diff --git a/log.c b/log.c
index 3cf3a0e6584a8d1b98a0660771916c0e169533d3..4043ab0c6a0b99fd4220c81b01f84e4d70b0babc 100644 (file)
--- a/log.c
+++ b/log.c
@@ -363,6 +363,7 @@ static void logfile_hup_notify(void *sst, int signum)
 {
     struct logfile *st=sst;
     FILE *f;
+    if (!st->logfile) return;
     f=fopen(st->logfile,"a");
     if (!f) {
        logfile_log(st,M_FATAL,"received SIGHUP, but could not reopen "
@@ -379,7 +380,7 @@ static void logfile_phase_hook(void *sst, uint32_t new_phase)
     struct logfile *st=sst;
     FILE *f;
 
-    if (background) {
+    if (background && st->logfile) {
        f=fopen(st->logfile,"a");
        if (!f) fatal_perror("logfile (%s:%d): cannot open \"%s\"",
                             st->loc.file,st->loc.line,st->logfile);
@@ -431,7 +432,7 @@ static list_t *logfile_apply(closure_t *self, struct cloc loc, dict_t *context,
     st->ops.vlogfn=logfile_vlog;
     st->ops.buff[0]=0;
     st->loc=loc;
-    st->f=NULL;
+    st->f=stderr;
     st->forked=0;
 
     item=list_elem(args,0);
@@ -440,7 +441,7 @@ static list_t *logfile_apply(closure_t *self, struct cloc loc, dict_t *context,
     }
     dict=item->data.dict;
 
-    st->logfile=dict_read_string(dict,"filename",True,"logfile",loc);
+    st->logfile=dict_read_string(dict,"filename",False,"logfile",loc);
     st->level=string_list_to_word(dict_lookup(dict,"class"),
                                       message_class_table,"logfile");