]> mj.ucw.cz Git - libucw.git/blobdiff - ucw/log-stream.c
tableprinter: code cleanup
[libucw.git] / ucw / log-stream.c
index 5af9f3e6581ad264797e64c566ba0573db40f5d8..342fe098872f6f213e7335826d92bbce930b55a8 100644 (file)
@@ -2,16 +2,16 @@
  *     UCW Library -- Logging: Management of Log Streams
  *
  *     (c) 2008 Tomas Gavenciak <gavento@ucw.cz>
- *     (c) 2009 Martin Mares <mj@ucw.cz>
+ *     (c) 2009--2012 Martin Mares <mj@ucw.cz>
  *
  *     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 <ucw/lib.h>
+#include <ucw/log.h>
+#include <ucw/log-internal.h>
+#include <ucw/simple-lists.h>
 
 #include <string.h>
 
@@ -24,7 +24,7 @@ static int log_initialized = 0;
 /* The head of the list of freed log_streams indexes in log_streams.ptr (~0U if none free).
  * Freed positions in log_streams.ptr are connected into a linked list in the following way:
  * log_streams.ptr[log_streams_free].levels is the index of next freed position (or ~0U) */
-static uns log_streams_free = ~0U;
+static uint log_streams_free = ~0U;
 
 /* Initialize the logstream module.
  * It is not neccessary to call this explicitely as it is called by
@@ -163,13 +163,22 @@ log_close_stream(struct log_stream *ls)
 }
 
 void
-log_set_format(struct log_stream *ls, uns mask, uns data)
+log_set_format(struct log_stream *ls, uint mask, uint data)
 {
   ls->msgfmt = (ls->msgfmt & mask) | 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)
@@ -179,7 +188,7 @@ int log_register_type(const char *name)
       log_type_names = xmalloc_zero(LS_NUM_TYPES * sizeof(char *));
       log_type_names[0] = "default";
     }
-  uns id;
+  uint 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);
@@ -196,7 +205,7 @@ int log_find_type(const char *name)
   if (!log_type_names)
     return -1;
 
-  for (uns id=0; id < LS_NUM_TYPES && log_type_names[id]; id++)
+  for (uint 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;