X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=ucw%2Flog-stream.c;h=5dbd71ff1c5bf63b3a090dc0d6693700eb9b4244;hb=117c8e6725fca812c6ef9ebc26d3133f980ecb7e;hp=3e94d74832ab678e1de24d4708c126e956facb1b;hpb=1e3a1935f1b1778b40a7d5276c7b2f8c311756e7;p=libucw.git diff --git a/ucw/log-stream.c b/ucw/log-stream.c index 3e94d748..5dbd71ff 100644 --- a/ucw/log-stream.c +++ b/ucw/log-stream.c @@ -2,16 +2,16 @@ * UCW Library -- Logging: Management of Log Streams * * (c) 2008 Tomas Gavenciak - * (c) 2009 Martin Mares + * (c) 2009--2012 Martin Mares * * This software may be freely distributed and used according to the terms * of the GNU Lesser General Public License. */ -#include "ucw/lib.h" -#include "ucw/log.h" -#include "ucw/log-internal.h" -#include "ucw/simple-lists.h" +#include +#include +#include +#include #include @@ -136,6 +136,7 @@ log_new_stream(size_t size) /* Initialize the stream */ bzero(l, sizeof(*l)); l->levels = ~0U; + l->types = ~0U; l->regnum = LS_SET_STRNUM(index); clist_init(&l->substreams); return log_ref_stream(l); @@ -168,3 +169,44 @@ log_set_format(struct log_stream *ls, uns mask, uns data) CLIST_FOR_EACH(simp_node *, i, ls->substreams) log_set_format(i->p, mask, data); } + +void +log_set_default_stream(struct log_stream *ls) +{ + struct log_stream *def = log_stream_by_flags(0); + log_rm_substream(def, NULL); + log_add_substream(def, ls); + log_close_stream(ls); +} + +/*** Registry of type names ***/ + +int log_register_type(const char *name) +{ + if (!log_type_names) + { + log_type_names = xmalloc_zero(LS_NUM_TYPES * sizeof(char *)); + log_type_names[0] = "default"; + } + uns id; + for (id=0; id < LS_NUM_TYPES && log_type_names[id]; id++) + if (!strcmp(log_type_names[id], name)) + return LS_SET_TYPE(id); + ASSERT(id < LS_NUM_TYPES); + log_type_names[id] = xstrdup(name); + return LS_SET_TYPE(id); +} + +/** Find a message type by name and return its ID encoded by `LS_SET_TYPE`. Returns -1 if no such type found. **/ +int log_find_type(const char *name) +{ + if (!strcmp(name, "default")) + return 0; + if (!log_type_names) + return -1; + + for (uns id=0; id < LS_NUM_TYPES && log_type_names[id]; id++) + if (!strcmp(log_type_names[id], name)) + return LS_SET_TYPE(id); + return -1; +}