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
00024 namespace Raul {
00025
00026 class LogBuffer : public std::streambuf
00027 {
00028 public:
00029 enum Colour {
00030 DEFAULT = 0,
00031 RED = 31,
00032 GREEN,
00033 YELLOW,
00034 BLUE,
00035 MAGENTA,
00036 CYAN,
00037 WHITE
00038 };
00039
00040 LogBuffer(const char* prefix="", Colour colour=DEFAULT)
00041 : _prefix(prefix)
00042 , _colour(colour)
00043 , _out(std::cout)
00044 {}
00045
00047 std::string colour(Colour c);
00048
00050 std::string plain();
00051
00052 protected:
00053 int_type overflow(int_type c) {
00054 if (c == '\n')
00055 emit();
00056 else if (c != traits_type::eof())
00057 _line += c;
00058
00059 return c;
00060 }
00061
00062 int sync() {
00063 if (!_line.empty())
00064 emit();
00065 return 0;
00066 }
00067
00068 private:
00069 void emit();
00070
00071 const char* _prefix;
00072 Colour _colour;
00073 std::string _line;
00074 std::ostream& _out;
00075 };
00076
00077
00078 class NullBuffer : public std::streambuf
00079 {
00080 protected:
00081 int_type overflow(int_type c) { return c; }
00082 int sync() { return 0; }
00083 };
00084
00085
00086 extern std::ostream info;
00087 extern std::ostream warn;
00088 extern std::ostream error;
00089 extern std::ostream debug;
00090
00091
00092 }
00093
00094 #endif // RAUL_LOG_HPP