chiark / gitweb /
log: Provide struct cfgfile_log
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 7 Dec 2019 16:29:21 +0000 (16:29 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 15 Feb 2020 21:56:51 +0000 (21:56 +0000)
This can be used as a logger during config reading.  system_log is not
available yet.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
log.c
secnet.h

diff --git a/log.c b/log.c
index e7d974dc853cfe1981afb9f1a3bdd474c0595118..3efd289fe67f9efc9051a07c84a2f83b58a06b51 100644 (file)
--- a/log.c
+++ b/log.c
@@ -176,6 +176,12 @@ void cfgfatal(struct cloc loc, cstring_t facility, const char *message, ...)
     va_end(args);
 }
 
+void cfgfile_log__vmsg(void *sst, int class, const char *message, va_list args)
+{
+    struct cfgfile_log *st=sst;
+    vcfgfatal_maybefile(0,st->loc,st->facility,message,args,"\n");
+}
+
 void cfgfile_postreadcheck(struct cloc loc, FILE *f)
 {
     assert(loc.file);
index c1397966b83d447abad4fb0288639030b68d0631..26a0b552608c35ac46500916d9a54d9b8599e1d6 100644 (file)
--- a/secnet.h
+++ b/secnet.h
@@ -640,6 +640,22 @@ FORMAT(printf,3,4);
 extern void vslilog_part(struct log_if *lf, int class, const char *message,
                         va_list) FORMAT(printf,3,0);
 
+void cfgfile_log__vmsg(void *sst, int class, const char *message, va_list);
+struct cfgfile_log {
+    struct log_if log;
+    /* private fields */
+    struct cloc loc;
+    const char *facility;
+};
+static inline void cfgfile_log_init(struct cfgfile_log *cfl,
+                                   struct cloc loc, const char *facility)
+{
+    cfl->log.st=cfl;
+    cfl->log.vlogfn=cfgfile_log__vmsg;
+    cfl->loc=loc;
+    cfl->facility=facility;
+}
+
 /* SITE interface */
 
 /* Pretty much a placeholder; allows starting and stopping of processing,