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 ce3a4d7..d06a71b 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 3cf3a0e..4043ab0 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");