X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=ucw%2Flog-stream.c;h=5af9f3e6581ad264797e64c566ba0573db40f5d8;hb=60418b4db60801d7c3fc995bf71f53ff5d898484;hp=f65373ce9cf4fe92fdf45e54e1007a8f063febe4;hpb=d22dba5a3ad6cd0e0be4c07527218c6b48fd5bd3;p=libucw.git diff --git a/ucw/log-stream.c b/ucw/log-stream.c index f65373ce..5af9f3e6 100644 --- a/ucw/log-stream.c +++ b/ucw/log-stream.c @@ -58,14 +58,20 @@ log_close_all(void) if (!log_initialized) return; - // Close all open streams + // Remove substreams of all streams for (int i=0; i < log_streams_after; i++) if (log_streams.ptr[i]->regnum >= 0) - log_close_stream(log_streams.ptr[i]); + log_rm_substream(log_streams.ptr[i], NULL); - // Free all cached structures + // Close all streams that remain and free all cached structures for (int i=0; i < log_streams_after; i++) - xfree(log_streams.ptr[i]); + { + struct log_stream *ls = log_streams.ptr[i]; + if (ls->regnum >= 0) + log_close_stream(ls); + ASSERT(ls->regnum < 0 || !ls->use_count); + xfree(ls); + } /* Back to the default state */ lsbuf_done(&log_streams); @@ -130,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); @@ -162,3 +169,35 @@ 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); } + +/*** 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; +}