• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

stream.h

Go to the documentation of this file.
00001 #ifndef WIBBLE_LOG_STREAM_H
00002 #define WIBBLE_LOG_STREAM_H
00003 
00004 #include <streambuf>
00005 #include <string>
00006 
00007 namespace wibble {
00008 namespace log {
00009 
00011 enum Level
00012 {
00013     DEBUG,
00014     INFO,
00015     UNUSUAL,
00016     WARN,
00017     ERR,
00018     CRIT
00019 };
00020 
00022 struct Sender
00023 {
00024     virtual ~Sender() {}
00030     virtual void send(Level level, const std::string& msg) = 0;
00031 };
00032 
00034 class Streambuf : public std::streambuf
00035 {
00036 protected:
00038     static const Level defaultLevel = INFO;
00040     std::string line;
00042     Level level;
00043 
00045     /* Note: we have to use composition instead of overloading because the
00046      * sender needs to be called in the destructor, and destructors cannot call
00047      * overridden methods */
00048     Sender* sender;
00049 
00051     void send();
00052 
00053 public:
00055     Streambuf();
00056 
00062     Streambuf(Sender* s);
00063     virtual ~Streambuf();
00064 
00066     void setSender(Sender* s);
00067 
00069     void setLevel(const Level& level);
00070 
00072     int overflow(int c);
00073 };
00074 
00075 std::ostream& operator<<(std::ostream& s, Level lev);
00076 
00077 }
00078 }
00079 
00080 // vim:set ts=4 sw=4:
00081 #endif

Generated on Tue May 10 2011 16:51:50 for wibble by  doxygen 1.7.1