]> mj.ucw.cz Git - libucw.git/commitdiff
Logging: Added log_set_format() and log_default_stream().
authorMartin Mares <mj@ucw.cz>
Sat, 14 Feb 2009 09:15:48 +0000 (10:15 +0100)
committerMartin Mares <mj@ucw.cz>
Sat, 14 Feb 2009 09:15:48 +0000 (10:15 +0100)
ucw/log-stream.c
ucw/log.c
ucw/log.h

index a7b10c821878bbe4bc1af465bcd5543ff24393c6..e4a7b31b54e553b8d9ec1ae7d4cdb674682037c2 100644 (file)
@@ -162,3 +162,11 @@ log_close_stream(struct log_stream *ls)
   ls->regnum = -1;
   return 1;
 }
+
+void
+log_set_format(struct log_stream *ls, uns mask, uns data)
+{
+  ls->msgfmt = (ls->msgfmt & mask) | data;
+  CLIST_FOR_EACH(simp_node *, i, ls->substreams)
+    log_set_format(i->p, mask, data);
+}
index 76821d981cdb73495a1a90fd59d59eeb4dd5131a..5f5d0ad8e109c72a30dfc4beba0b92d8f85823dd 100644 (file)
--- a/ucw/log.c
+++ b/ucw/log.c
@@ -333,6 +333,8 @@ int main(void)
 {
   struct log_stream *ls = log_new_syslog(LOG_USER, "syslog");
   msg(L_INFO | ls->regnum, "Brum <%300s>", ":-)");
+  log_set_format(log_default_stream(), ~0U, LSFMT_USEC);
+  msg(L_INFO, "Brum <%300s>", ":-)");
   return 0;
 }
 
index d87c389638a4ebdfc9bb3fae91089fae1f7a11c8..bbecb0fce4c676ce33914797ec871bd2b3d90507 100644 (file)
--- a/ucw/log.h
+++ b/ucw/log.h
@@ -149,11 +149,20 @@ void log_add_substream(struct log_stream *where, struct log_stream *what);
 /* return number of deleted entries */
 int log_rm_substream(struct log_stream *where, struct log_stream *what);
 
+/* Set formatting flags of a given stream and all its substreams. The flags are
+ * ANDed with @mask and ORed with @data. */
+void log_set_format(struct log_stream *ls, uns mask, uns data);
+
 /* get a stream by its number (regnum) */
 /* returns NULL for free numbers */
 /* defaults to ls_default_stream for 0 when stream number 0 not set */
 struct log_stream *log_stream_by_flags(uns flags);
 
+static inline struct log_stream *log_default_stream(void)
+{
+  return log_stream_by_flags(0);
+}
+
 /* process a message (string) (INTERNAL) */
 /* depth prevents undetected looping */
 /* returns 1 in case of loop detection or other fatal error