00001 #ifndef LOGGERBASE_H
00002 #define LOGGERBASE_H
00003
00004
00005 #include <map>
00006 #include <iostream>
00007 #include <fstream>
00008 #include <sstream>
00009
00010 namespace PSQt {
00011
00012
00013
00014
00015
00016
00017
00018
00019 enum LEVEL {DEBUG=0, INFO, WARNING, CRITICAL, ERROR, NONE};
00020
00021
00022
00023
00024
00025
00026
00027
00028 struct Record {
00029 unsigned number;
00030 double time;
00031 std::string tstamp;
00032 LEVEL level;
00033 std::string name;
00034 std::string msg;
00035
00036 std::string strRecordTotal();
00037 std::string strRecordBrief();
00038 std::string strRecord();
00039 };
00040
00041
00042
00043 std::string strLevel(const LEVEL& level=DEBUG) ;
00044 LEVEL levelFromString(const std::string& str="INFO");
00045 std::string strTimeStamp(const std::string& format=std::string("%Y-%m-%d-%H:%M:%S"));
00046 double doubleTimeNow();
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089 class LoggerBase
00090 {
00091 public:
00092
00093
00094
00095
00096
00097
00098 LoggerBase(const LEVEL& level=INFO);
00099 virtual ~LoggerBase(){};
00100
00101 void message(const std::string& name=std::string(), const LEVEL& level=INFO, const std::string& msg=std::string());
00102 void message(const std::string& name=std::string(), const LEVEL& level=INFO, const std::stringstream& ss=std::stringstream());
00103 void print(const std::string& str=std::string());
00104 void setLevel(const LEVEL& level=INFO);
00105 LEVEL getLevel() { return m_level; }
00106 void saveLogInFile(const std::string& fname=std::string(), const bool& add_tstamp=true) ;
00107 std::string strRecordsForLevel(const LEVEL& thr=INFO);
00108
00109 protected:
00110 virtual void new_record(Record& rec);
00111
00112 private:
00113
00114 unsigned m_recnum;
00115 LEVEL m_level;
00116 std::string m_start_tstamp;
00117 double m_start_time;
00118
00119 std::map<unsigned, Record> m_sslog;
00120
00121 inline const char* _name_(){return "LoggerBase";}
00122 void startLoggerBase();
00123 std::string getFileName(const std::string& fname=std::string(), const bool& add_tstamp=true);
00124 };
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135 }
00136
00137 #endif // LOGGERBASE_H
00138
00139
00140
00141