WvStreams
wvlogbuffer.h
1/* -*- Mode: C++ -*-
2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
4 *
5 */
6#ifndef __WVLOGBUFFER_H
7#define __WVLOGBUFFER_H
8
9#include "wvlogrcv.h"
10#include "wvhashtable.h"
11
17class WvLogBuffer : public WvLogRcv
18{
19public:
20 // An actual message
21 class Msg
22 {
23 public:
24 time_t timestamp;
25 WvLog::LogLevel level;
26 WvString source, message;
27
28 Msg(WvLog::LogLevel _level, WvStringParm _source, WvString _message);
29 };
30
31 DeclareWvList(Msg);
32
33 /*
34 * Maps a string describing msg type of the form "source:level"
35 * to a list of pointers to all messages of this type
36 */
38 {
39 public:
40 MsgCounter(WvString _src_lvl) : src_lvl(_src_lvl) {};
41 Msg* add(Msg* msg, int max);
42 WvString src_lvl;
43 private:
44 MsgList list;
45 };
46
47 DeclareWvDict(MsgCounter, WvString, src_lvl);
48
49protected:
50 /*
51 * "Owns" all the msges
52 */
53 MsgList msgs;
54 /*
55 * Used for keeping track of how many messages from a given source/level
56 * there are. Just stores the pointers.
57 */
58 MsgCounterDict counters;
59 WvDynBuf current;
60 int max_lines;
61
62 void handle_msg(Msg *lastmsg);
63
64 virtual void _begin_line() {};
65 virtual void _mid_line(const char *str, size_t len);
66 virtual void _end_line();
67
68public:
69 WvLogBuffer(int _max_lines,
70 WvLog::LogLevel _max_level = WvLog::NUM_LOGLEVELS);
71 virtual ~WvLogBuffer();
72
73 MsgList &messages()
74 { end_line(); return msgs; }
75
76 void feed_receiver(WvLogRcv& receiver);
77
78 void dump(WvStream &s);
79};
80
81#endif // __WVLOGBUFFER_H
A WvFastString acts exactly like a WvString, but can take (const char *) strings without needing to a...
Definition: wvstring.h:94
WvLogBuffer is a descendant of WvLogRcv that buffers log messages for later use.
Definition: wvlogbuffer.h:18
virtual void _end_line()
End this (Guaranteed NonEmpty) log line.
Definition: wvlogbuffer.cc:75
virtual void _mid_line(const char *str, size_t len)
add text to the current log line.
Definition: wvlogbuffer.cc:48
virtual void _begin_line()
Start a new log line (print prefix)
Definition: wvlogbuffer.h:64
WvLogRcv adds some intelligence to WvLogRcvBase, to keep track of line-prefix-printing and other form...
Definition: wvlogrcv.h:29
Unified support for streams, that is, sequences of bytes that may or may not be ready for read/write ...
Definition: wvstream.h:25
WvString is an implementation of a simple and efficient printable-string class.
Definition: wvstring.h:330