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 
7 namespace wibble {
8 namespace log {
9 
11 enum Level
12 {
17  ERR,
19 };
20 
22 struct Sender
23 {
24  virtual ~Sender() {}
30  virtual void send(Level level, const std::string& msg) = 0;
31 };
32 
34 class Streambuf : public std::streambuf
35 {
36 protected:
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 
53 public:
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 
78 std::ostream& operator<<(std::ostream& s, Level lev);
79 
80 }
81 }
82 
83 // vim:set ts=4 sw=4:
84 #endif
Level
Urgency of a log message.
Definition: stream.h:11
virtual ~Sender()
Definition: stream.h:24
Sender * sender
Sender used to send log messages.
Definition: stream.h:48
Definition: stream.h:14
Definition: stream.h:16
Level level
Level of the next log message.
Definition: stream.h:42
Handle sending a log message.
Definition: stream.h:22
Definition: stream.h:13
Streambuf class for logging.
Definition: stream.h:34
std::ostream & operator<<(std::ostream &s, Level lev)
Definition: stream.cpp:47
Definition: amorph.h:17
Definition: stream.h:18
std::string line
Line buffer with the log message we are building.
Definition: stream.h:40
Definition: stream.h:15
virtual void send(Level level, const std::string &msg)=0
Log one line of text with the given level.
Definition: stream.h:17