#include "ucw/lib.h"
#include "ucw/log.h"
+#include "ucw/log-internal.h"
#include "ucw/simple-lists.h"
#include <stdio.h>
/*** The default log stream, which logs to stderr ***/
-static int default_log_handler(struct log_stream *ls, struct log_msg *m)
+static int default_log_handler(struct log_stream *ls UNUSED, struct log_msg *m)
{
// This is a completely bare version of the log-file module. Errors are ignored.
- write(ls->idata, m->m, m->m_len);
+ write(2, m->m, m->m_len);
return 0;
}
struct log_stream log_stream_default = {
.name = "stderr",
- .idata = 2,
.use_count = 1000000,
.handler = default_log_handler,
- .levels = LS_ALL_LEVELS,
+ .levels = ~0U,
.msgfmt = LSFMT_DEFAULT,
// an empty clist
.substreams.head.next = (cnode *) &log_stream_default.substreams.head,
{
int n = LS_GET_STRNUM(flags);
if (n < 0 || n >= log_streams_after || log_streams.ptr[n]->regnum == -1)
- return (n ? NULL : LOG_STREAM_DEFAULT);
+ return (n ? NULL : &log_stream_default);
return log_streams.ptr[n];
}
/* Check the stream existence */
if (!ls)
{
- msg((LS_INTERNAL_MASK&cat)|L_WARN, "No log_stream with number %d! Logging to the default log.", LS_GET_STRNUM(cat));
- ls = LOG_STREAM_DEFAULT;
+ msg((LS_CTRL_MASK&cat)|L_WARN, "No log_stream with number %d! Logging to the default log.", LS_GET_STRNUM(cat));
+ ls = &log_stream_default;
}
/* Get the current time */
- if (!(cat & LSFLAG_SIGHANDLER))
+ if (!(cat & L_SIGHANDLER))
{
/* CAVEAT: These calls are not safe in signal handlers. */
gettimeofday(&tv, NULL);
if (log_pass_msg(0, ls, &m))
{
/* Error (such as infinite loop) occurred */
- log_pass_msg(0, LOG_STREAM_DEFAULT, &m);
+ log_pass_msg(0, &log_stream_default, &m);
}
if (m.raw_msg != msgbuf)
if (depth > LS_MAX_DEPTH)
{
struct log_msg errm = *m;
- errm.flags = L_ERROR | (m->flags & LS_INTERNAL_MASK);
+ errm.flags = L_ERROR | (m->flags & LS_CTRL_MASK);
errm.raw_msg = "Loop in the log_stream system detected.";
- log_pass_msg(0, LOG_STREAM_DEFAULT, &errm);
+ log_pass_msg(0, &log_stream_default, &errm);
}
/* Filter by level and hook function */
{
struct log_stream *ls = log_new_syslog(LOG_USER, "syslog");
msg(L_INFO | ls->regnum, "Brum <%300s>", ":-)");
+ log_set_format(log_default_stream(), ~0U, LSFMT_USEC);
+ msg(L_INFO, "Brum <%300s>", ":-)");
return 0;
}