wibble 1.1
stream.h
Go to the documentation of this file.
1#ifndef WIBBLE_LOG_STREAM_H
2#define WIBBLE_LOG_STREAM_H
3
4#include <streambuf>
5#include <string>
6
7namespace wibble {
8namespace log {
9
20
22struct Sender
23{
24 virtual ~Sender() {}
30 virtual void send(Level level, const std::string& msg) = 0;
31};
32
34class Streambuf : public std::streambuf
35{
36protected:
38 static const Level defaultLevel = INFO;
40 std::string line;
43
45 /* Note: we have to use composition instead of overloading because the
46 * sender needs to be called in the destructor, and destructors cannot call
47 * overridden methods */
49
51 void send();
52
53public:
55 Streambuf();
56
62 Streambuf(Sender* s);
63 virtual ~Streambuf();
64
66 void send_partial_line();
67
69 void setSender(Sender* s);
70
72 void setLevel(const Level& level);
73
75 int overflow(int c);
76};
77
78std::ostream& operator<<(std::ostream& s, Level lev);
79
80}
81}
82
83// vim:set ts=4 sw=4:
84#endif
Streambuf class for logging.
Definition stream.h:35
void send()
Send the message "line" with the level "level".
Definition stream.cpp:24
Level level
Level of the next log message.
Definition stream.h:42
void setSender(Sender *s)
Set/change the sender to use for this streambuf.
Definition stream.cpp:22
Sender * sender
Sender used to send log messages.
Definition stream.h:48
virtual ~Streambuf()
Definition stream.cpp:11
void send_partial_line()
If there is a partial line, send it out.
Definition stream.cpp:16
std::string line
Line buffer with the log message we are building.
Definition stream.h:40
int overflow(int c)
override to get data as a std::streambuf
Definition stream.cpp:38
static const Level defaultLevel
Level to use for messages whose level has not been specified.
Definition stream.h:38
void setLevel(const Level &level)
Set the level for the next message, and the next message only.
Definition stream.cpp:33
Streambuf()
Construct a nonworking Streambuf to be initialised later.
Definition stream.cpp:7
std::ostream & operator<<(std::ostream &s, Level lev)
Definition stream.cpp:47
Level
Urgency of a log message.
Definition stream.h:12
@ WARN
Definition stream.h:16
@ INFO
Definition stream.h:14
@ CRIT
Definition stream.h:18
@ DEBUG
Definition stream.h:13
@ ERR
Definition stream.h:17
@ UNUSUAL
Definition stream.h:15
Definition amorph.h:17
Definition amorph.h:30
Handle sending a log message.
Definition stream.h:23
virtual void send(Level level, const std::string &msg)=0
Log one line of text with the given level.
virtual ~Sender()
Definition stream.h:24