2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
5 * Enhanced "Log Receiver" classes for WvLog.
7 * WvLogRcv-derived classes support automatic formatting of log lines with
8 * a prefix, removing control characters, and so on.
10 * WvLogRcv supports partial- and multiple-line log messages. For example,
12 * log.print("string\nfoo");
14 * appname(lvl): test string
21 #include "wvfdstream.h"
22 #include "wvscatterhash.h"
25 * WvLogRcv adds some intelligence to WvLogRcvBase, to keep
26 * track of line-prefix-printing and other formatting information.
28 class WvLogRcv
: public WvLogRcvBase
32 WvLog::LogLevel max_level
, last_level
;
43 Src_Lvl(WvString _src
, int _lvl
) : src(_src
),
44 lvl((WvLog::LogLevel
)_lvl
) {};
47 DeclareWvScatterDict(Src_Lvl
, WvString
, src
);
49 Src_LvlDict custom_levels
;
51 /** Set the Prefix and Prefix Length (size_t prelen) */
52 virtual void _make_prefix(time_t now
);
54 /** Start a new log line (print prefix) */
55 virtual void _begin_line();
57 /** End this (Guaranteed NonEmpty) log line */
58 virtual void _end_line();
61 * add text to the current log line. 'str' may contain only
62 * one '\n' optional character at str[len-1] (the end); if it does,
63 * end_line will be called immediately after this function.
65 virtual void _mid_line(const char *str
, size_t len
) = 0;
69 { if (!at_newline
) return; _begin_line(); at_newline
= false; }
70 void mid_line(const char *str
, size_t len
)
71 { _mid_line(str
, len
);
72 if (len
>0 && str
[len
-1] == '\n') at_newline
= true; }
75 virtual void log(WvStringParm source
, int loglevel
,
76 const char *_buf
, size_t len
);
78 static const char *loglevels
[WvLog::NUM_LOGLEVELS
];
80 WvLogRcv(WvLog::LogLevel _max_level
= WvLog::NUM_LOGLEVELS
);
84 { if (at_newline
) return;
85 _mid_line("\n", 1); _end_line(); at_newline
= true; };
87 WvLog::LogLevel
level() const
89 void level(WvLog::LogLevel lvl
)
93 * Allows you to override debug levels for specific sources
94 * example: mysql=9,Service Manager=9
95 * will get all the debug output from all the sources that
96 * contain (case insensitively) "mysql" or "Service Manager"
97 * in the source name regardless of the current debug level.
99 bool set_custom_levels(WvString descr
);
104 * Captures formatted log messages and outputs them to the
105 * specified file descriptor.
107 class WvLogConsole
: public WvFDStream
, public WvLogRcv
110 WvLogConsole(int _fd
,
111 WvLog::LogLevel _max_level
= WvLog::NUM_LOGLEVELS
);
112 virtual ~WvLogConsole();
114 virtual void _mid_line(const char *str
, size_t len
);
117 #endif // __WVLOGRCV_H