]> mj.ucw.cz Git - libucw.git/commitdiff
Logging: Added log_set_default_stream()
authorMartin Mares <mj@ucw.cz>
Sat, 7 Jan 2012 13:33:43 +0000 (14:33 +0100)
committerMartin Mares <mj@ucw.cz>
Sat, 7 Jan 2012 13:33:43 +0000 (14:33 +0100)
ucw/doc/log.txt
ucw/log-stream.c
ucw/log.h

index 28265f7290af6c4795cb5d85e8736f75df062435..61e443e9651e0355df5ab85a3585fcbc57489354 100644 (file)
@@ -64,9 +64,9 @@ When a log stream receives a message, it is processed as follows:
 When no stream is explicitly selected, msg() uses the default stream, which
 has registration number 0 and which is also returned by log_default_stream().
 This stream has no explicit destination, but it can have substreams. (When
-a program starts, the default stream is connected to stderr; a call to log_file()
+a program starts, the default stream is connected to stderr. A call to log_file()
 establishes a file logging stream and links it as the only substream of the
-default stream.)
+default stream. If you want to do that with any other log stream, call log_set_default_stream().)
 
 Streams are reference-counted. When a stream is created, it gets reference count 1.
 When it is linked as a substream of another stream, its reference count is incremented.
index 5af9f3e6581ad264797e64c566ba0573db40f5d8..2cc9f7a05bfa835dae8cdab41f0a76d86a8a4f6d 100644 (file)
@@ -2,7 +2,7 @@
  *     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.
@@ -170,6 +170,15 @@ log_set_format(struct log_stream *ls, uns mask, uns data)
     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)
index f2d99a0729d19e5ff79fdd06a26946743654d8d8..5e8d4ef52b993210f864d3d3b97e73272a81e2b5 100644 (file)
--- a/ucw/log.h
+++ b/ucw/log.h
@@ -179,6 +179,17 @@ static inline struct log_stream *log_default_stream(void)
   return log_stream_by_flags(0);
 }
 
+/**
+ * Make the specified stream the default destination.
+ *
+ * In fact, it takes the fixed default stream and attaches @ls as its only
+ * substream. If there were any other substreams, they are removed.
+ *
+ * Log streams created by log_file() or log_configured() are made default
+ * by calling this function.
+ **/
+void log_set_default_stream(struct log_stream *ls);
+
 /**
  * Close all open streams, un-initialize the module, free all memory and
  * reset the logging mechanism to use stderr only.