WvStreams
debian/libwvstreams-dev/usr/include/wvstreams/wvlogrcv.h
1/* -*- Mode: C++ -*-
2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
4 *
5 * Enhanced "Log Receiver" classes for WvLog.
6 *
7 * WvLogRcv-derived classes support automatic formatting of log lines with
8 * a prefix, removing control characters, and so on.
9 *
10 * WvLogRcv supports partial- and multiple-line log messages. For example,
11 * log.print("test ");
12 * log.print("string\nfoo");
13 * will print:
14 * appname(lvl): test string
15 * appname(lvl): foo
16 */
17#ifndef __WVLOGRCV_H
18#define __WVLOGRCV_H
19
20#include "wvlog.h"
21#include "wvfdstream.h"
22#include "wvscatterhash.h"
23
28class WvLogRcv : public WvLogRcvBase
29{
30protected:
31 WvString last_source;
32 WvLog::LogLevel max_level, last_level;
33 time_t last_time;
34 bool at_newline;
35 WvString prefix;
36 size_t prelen;
37
38 class Src_Lvl
39 {
40 public:
41 WvString src;
42 WvLog::LogLevel lvl;
43 Src_Lvl(WvString _src, int _lvl) : src(_src),
44 lvl((WvLog::LogLevel)_lvl) {};
45 };
46
47 DeclareWvScatterDict(Src_Lvl, WvString, src);
48
49 Src_LvlDict custom_levels;
50
52 virtual void _make_prefix(time_t now);
53
55 virtual void _begin_line();
56
58 virtual void _end_line();
59
65 virtual void _mid_line(const char *str, size_t len) = 0;
66
67private:
68 void begin_line()
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; }
73
74public:
75 virtual void log(WvStringParm source, int loglevel,
76 const char *_buf, size_t len);
77
78 static const char *loglevels[WvLog::NUM_LOGLEVELS];
79
80 WvLogRcv(WvLog::LogLevel _max_level = WvLog::NUM_LOGLEVELS);
81 virtual ~WvLogRcv();
82
83 void end_line()
84 { if (at_newline) return;
85 _mid_line("\n", 1); _end_line(); at_newline = true; };
86
87 WvLog::LogLevel level() const
88 { return max_level; }
89 void level(WvLog::LogLevel lvl)
90 { max_level = lvl; }
91
92 /*
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.
98 */
99 bool set_custom_levels(WvString descr);
100};
101
102
107class WvLogConsole : public WvFDStream, public WvLogRcv
108{
109 public:
110 WvLogConsole(int _fd,
111 WvLog::LogLevel _max_level = WvLog::NUM_LOGLEVELS);
112 virtual ~WvLogConsole();
113 protected:
114 virtual void _mid_line(const char *str, size_t len);
115};
116
117#endif // __WVLOGRCV_H
A WvFastString acts exactly like a WvString, but can take (const char *) strings without needing to a...
Base class for streams built on Unix file descriptors.
Captures formatted log messages and outputs them to the specified file descriptor.
virtual void _mid_line(const char *str, size_t len)
add text to the current log line.
Definition wvlog.cc:432
WvLogRcv adds some intelligence to WvLogRcvBase, to keep track of line-prefix-printing and other form...
virtual void _end_line()
End this (Guaranteed NonEmpty) log line.
Definition wvlog.cc:254
virtual void _make_prefix(time_t now)
Set the Prefix and Prefix Length (size_t prelen)
Definition wvlog.cc:240
virtual void _begin_line()
Start a new log line (print prefix)
Definition wvlog.cc:248
virtual void _mid_line(const char *str, size_t len)=0
add text to the current log line.
WvString is an implementation of a simple and efficient printable-string class.