9#include "wvlogbuffer.h"
13WvLogBuffer::Msg::Msg(WvLog::LogLevel _level,
WvStringParm _source,
14 WvString _message) : level(_level), source(_source), message(_message)
21 list.append(msg,
false);
24 if (list.count() > (
size_t)max)
26 Msg* killme = list.first();
35WvLogBuffer::WvLogBuffer(
int _max_lines, WvLog::LogLevel _max_level) :
38 max_lines = _max_lines;
42WvLogBuffer::~WvLogBuffer()
50 current.put(str, len);
53void WvLogBuffer::handle_msg(Msg *lastmsg)
56 msgs.append(lastmsg,
true);
60 MsgCounter* msgcounter = counters[type];
64 msgcounter =
new MsgCounter(type);
65 counters.add(msgcounter,
true);
68 Msg* killme = msgcounter->add(lastmsg, max_lines);
77 if (last_level < WvLog::NUM_LOGLEVELS)
80 Msg *lastmsg =
new Msg(last_level, last_source,
89void WvLogBuffer::feed_receiver(
WvLogRcv& receiver)
91 WvLogBuffer::MsgList::Iter i(msgs);
96 receiver.log(msg.source, msg.level,
97 msg.message.
cstr(), msg.message.len());
104 MsgList::Iter i(messages());
106 for (i.rewind(); i.next(); )
109 s.print(
"%s %s<%s>: %s+\n",
110 m.timestamp, m.source, loglevels[m.level], m.message);
const T * get(size_t count)
Reads exactly the specified number of elements and returns a pointer to a storage location owned by t...
void zap()
Clears the buffer.
size_t used() const
Returns the number of elements in the buffer currently available for reading.
A WvFastString acts exactly like a WvString, but can take (const char *) strings without needing to a...
const char * cstr() const
return a (const char *) for this string.
virtual void _end_line()
End this (Guaranteed NonEmpty) log line.
virtual void _mid_line(const char *str, size_t len)
add text to the current log line.
WvLogRcv adds some intelligence to WvLogRcvBase, to keep track of line-prefix-printing and other form...
Unified support for streams, that is, sequences of bytes that may or may not be ready for read/write ...
WvString is an implementation of a simple and efficient printable-string class.
char * trim_string(char *string)
Trims whitespace from the beginning and end of the character string, including carriage return / line...