4 #include <wvlogstream.h>
6 #include <wvlinkerhack.h>
7 #include <wvistreamlist.h>
12 static WvLog
*wvlog
= NULL
;
13 static WvLogRcv
*rcv
= NULL
;
16 static WvString log_moniker
;
18 WV_LINK_TO(WvConStream
);
19 WV_LINK_TO(WvTCPConn
);
20 WV_LINK_TO(WvSSLStream
);
21 WV_LINK_TO(WvGzipStream
);
23 WV_LINK_TO(WvUnixConn
);
26 struct pstring
wvlog_get_moniker()
28 const int safe_size
= 1024;
29 log_moniker
.setsize(safe_size
);
30 struct pstring ret
= { log_moniker
.edit(), safe_size
};
39 class WvNullRcv
: public WvLogRcv
42 WvNullRcv() : WvLogRcv(WvLog::Info
) {}
46 virtual void _mid_line(const char *str
, size_t len
) {}
54 else // This will only be true once; when we first call this function
55 setup_console_crash();
61 if (log_level
>= (int)WvLog::NUM_LOGLEVELS
)
63 else if (log_level
>= 1)
64 pri
= (WvLog::LogLevel
)log_level
;
68 IWvStream
*s
= wvcreate
<IWvStream
>(log_moniker
);
70 rcv
= new WvLogStream(s
, pri
);
72 wvlog
= new WvLog(getpid(), WvLog::Debug
);
74 (*wvlog
)(WvLog::Notice
, "Log initialized. (log_level=%s)\n",
77 else // We want this to also capture (and eliminate) DBus messages.
78 rcv
= new WvNullRcv();
82 void wvlog_print(const char *file
, int line
, const char *s
)
86 while (WvIStreamList::globallist
.select(0))
87 WvIStreamList::globallist
.callback();
88 WvString
ss("%s:%s: %s", file
, line
, s
);
95 if (wvlog
) (*wvlog
)(WvLog::Info
, "Log closing.\n");
96 if (wvlog
) delete wvlog
;