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.
* 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.
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)
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.