00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef RAUL_LOG_HPP
00019 #define RAUL_LOG_HPP
00020
00021 #include <iostream>
00022 #include <sstream>
00023 #include <string>
00024
00025 namespace Raul {
00026
00030 class LogBuffer : public std::streambuf
00031 {
00032 public:
00033 enum Colour {
00034 DEFAULT = 0,
00035 RED = 31,
00036 GREEN,
00037 YELLOW,
00038 BLUE,
00039 MAGENTA,
00040 CYAN,
00041 WHITE
00042 };
00043
00044 LogBuffer(const char* prefix="", Colour colour=DEFAULT)
00045 : _prefix(prefix)
00046 , _colour(colour)
00047 , _out(std::cout)
00048 {}
00049
00051 std::string colour(Colour c);
00052
00054 std::string plain();
00055
00056 protected:
00057 int_type overflow(int_type c) {
00058 if (c == '\n')
00059 emit();
00060 else if (c != traits_type::eof())
00061 _line += c;
00062
00063 return c;
00064 }
00065
00066 int sync() {
00067 if (!_line.empty())
00068 emit();
00069 return 0;
00070 }
00071
00072 private:
00073 void emit();
00074
00075 const char* _prefix;
00076 Colour _colour;
00077 std::string _line;
00078 std::ostream& _out;
00079 };
00080
00081
00082 class NullBuffer : public std::streambuf
00083 {
00084 protected:
00085 int_type overflow(int_type c) { return c; }
00086 int sync() { return 0; }
00087 };
00088
00089
00090 extern std::ostream info;
00091 extern std::ostream warn;
00092 extern std::ostream error;
00093 extern std::ostream debug;
00094
00095
00096 }
00097
00098 #endif // RAUL_LOG_HPP