00001
00002
00003
00004
00005
00006
00007
00008
00009
00023 #ifndef __LOG_H__
00024 #define __LOG_H__
00025
00026 #include <iostream>
00027 #include <string>
00028 #include <fstream>
00029 #include <ctime>
00030
00031 namespace LogNS {
00036 typedef void (*cfunction) ();
00043 typedef enum severity{ info, low, high, critic, none } severity;
00044
00055 const int CERR=1;
00056 const int OUTFILE=2;
00058 const std::string black="\033[30m";
00059 const std::string red="\033[31m";
00060 const std::string green="\033[32m";
00061 const std::string brown="\033[33m";
00062 const std::string blue="\033[34m";
00063 const std::string magenta="\033[35m";
00064 const std::string cyan="\033[36m";
00065 const std::string white="\033[37m";
00066
00067 class Log {
00068
00069 private:
00070 time_t log_time;
00071 struct tm *tt;
00072 bool log_exit;
00073 severity _level;
00074 std::ofstream *_out;
00075 bool _cerr_out;
00076 cfunction critic_function;
00077 std::string _scheme_color[6];
00078 bool color;
00079 Log(const severity &level=info, const int &mode=0, const std::string &file ="", bool append_date=true);
00080 Log(const Log& log) {}
00081 Log& operator=(const Log& log) {return *this;}
00082
00083 public:
00084 ~Log();
00085 static Log& logger();
00086
00087 void set_output(const int& mode=0, const std::string& file="", bool append_date=true);
00088
00089
00090 severity change_level(const severity &level);
00091 severity get_level();
00092 std::ofstream& get_outstream();
00093 bool cerr_out();
00094 bool file_out();
00095 void log(const severity &level, const std::string &message);
00096 void log(const std::string &message);
00097 bool exit_on_critic(bool ans);
00098 cfunction set_critic_function(cfunction);
00099 void set_color_scheme(const std::string info=black, const std::string low=brown, const std::string high=magenta, const std::string critic=red);
00100 void no_color_scheme();
00101
00102 #ifndef SWIG
00103 friend Log& operator<<( Log &log, std::string message);
00104 #endif
00105 };
00106 }
00107
00183 #endif //__LOG_H__