From: Martin Mares Date: Sat, 14 Feb 2009 09:15:48 +0000 (+0100) Subject: Logging: Added log_set_format() and log_default_stream(). X-Git-Tag: holmes-import~88 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=5caf33ebad2737a016171492525aca58cccf77c1;p=libucw.git Logging: Added log_set_format() and log_default_stream(). --- diff --git a/ucw/log-stream.c b/ucw/log-stream.c index a7b10c82..e4a7b31b 100644 --- a/ucw/log-stream.c +++ b/ucw/log-stream.c @@ -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); +} diff --git a/ucw/log.c b/ucw/log.c index 76821d98..5f5d0ad8 100644 --- 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; } diff --git a/ucw/log.h b/ucw/log.h index d87c3896..bbecb0fc 100644 --- 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