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 
17 class WvLogBuffer : public WvLogRcv
18 {
19 public:
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  */
37  class MsgCounter
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 
49 protected:
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 
68 public:
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
WvLogBuffer::_begin_line
virtual void _begin_line()
Start a new log line (print prefix)
Definition: wvlogbuffer.h:64
WvLogBuffer::_mid_line
virtual void _mid_line(const char *str, size_t len)
add text to the current log line.
Definition: wvlogbuffer.cc:48
WvString
WvString is an implementation of a simple and efficient printable-string class.
Definition: wvstring.h:329
WvLogBuffer::MsgCounter
Definition: wvlogbuffer.h:37
WvLogRcv
WvLogRcv adds some intelligence to WvLogRcvBase, to keep track of line-prefix-printing and other form...
Definition: wvlogrcv.h:28
WvLogBuffer::Msg
Definition: wvlogbuffer.h:21
WvStream
Unified support for streams, that is, sequences of bytes that may or may not be ready for read/write ...
Definition: wvstream.h:24
WvLogBuffer
WvLogBuffer is a descendant of WvLogRcv that buffers log messages for later use.
Definition: wvlogbuffer.h:17
WvDynBufBase< unsigned char >
WvLogBuffer::_end_line
virtual void _end_line()
End this (Guaranteed NonEmpty) log line.
Definition: wvlogbuffer.cc:75