33 const char *appname(WvStringParm log)
const;
34 virtual void log(WvStringParm source,
int loglevel,
35 const char *_buf,
size_t len) = 0;
38 static void cleanup_on_fork(pid_t p);
39 static void static_init();
44 virtual ~WvLogRcvBase();
50typedef wv::function<
WvString(WvStringParm)> WvLogFilter;
58 friend class WvLogRcvBase;
78 static WvLogRcvBaseList *receivers;
79 static int num_receivers, num_logs;
80 static WvLogRcvBase *default_receiver;
84 WvLog(WvStringParm _app, LogLevel _loglevel = Info,
85 WvLogFilter* filter = 0);
86 WvLog(
const WvLog &l);
90 virtual bool isok()
const;
100 WvLog &
lvl(LogLevel _loglevel)
101 { loglevel = _loglevel;
return *
this; }
106 LogLevel l = loglevel;
107 size_t x =
lvl(_loglevel).
write(filter ? (*filter)(s) : s);
115 LogLevel l = loglevel;
118 x =
lvl(_loglevel).print((*filter)(
WvString(WVSTRING_FORMAT_CALL)));
120 x =
lvl(_loglevel).print(WVSTRING_FORMAT_CALL);
130 {
return WvStream::operator()(filter ? (*filter)(s) : s); }
133 WvStream::operator()((*filter)(
WvString(WVSTRING_FORMAT_CALL))) :
134 WvStream::operator()(WVSTRING_FORMAT_CALL) );
142 WvLog
split(LogLevel _loglevel)
const
143 {
return WvLog(app, _loglevel, filter); }
149 virtual size_t uwrite(
const void *buf,
size_t len);
153 { print(
"%s: %s\n", s,
strerror(errno)); }
156 const char *wstype()
const {
return "WvLog"; }
static WvString strerror(int errnum)
A replacement for the operating system strerror() function that can map more kinds of error strings (...
A WvLog stream accepts log messages from applications and forwards them to all registered WvLogRcv's.
WvLog & lvl(LogLevel _loglevel)
change the loglevel.
virtual bool isok() const
fd==-1, but this stream is always ok
virtual bool post_select(SelectInfo &si)
post_select() is called after select(), and returns true if this object is now ready.
WvLog split(LogLevel _loglevel) const
split off a new WvLog object with the requested loglevel.
size_t operator()(LogLevel _loglevel, WvStringParm s)
change the loglevel and then print a message.
virtual size_t uwrite(const void *buf, size_t len)
we override the unbuffered write function, so lines also include the application and log level.
void perror(WvStringParm s)
a useful substitute for the normal C perror() function
virtual void pre_select(SelectInfo &si)
pre_select() sets up for eventually calling select().
WvStream()
Basic constructor for just a do-nothing WvStream.
virtual size_t write(const void *buf, size_t count)
Write data to the stream.
WvString is an implementation of a simple and efficient printable-string class.
the data structure used by pre_select()/post_select() and internally by select().