From: Ian Jackson Date: Sat, 23 Nov 2019 17:50:28 +0000 (+0000) Subject: logfile: Log to stderr by default (`filename' key now optional) X-Git-Tag: v0.6.0~246 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=secnet.git;a=commitdiff_plain;h=44caf412a762e8b90d6731aa967020a043ea0849 logfile: Log to stderr by default (`filename' key now optional) Signed-off-by: Ian Jackson --- diff --git a/README b/README index ce3a4d7..d06a71b 100644 --- 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 --- 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");