Logger.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef _OPENCOG_LOGGER_H
00028 #define _OPENCOG_LOGGER_H
00029
00030 #include <string>
00031
00032 #include <cstdarg>
00033 #include <pthread.h>
00034
00035
00036
00037
00038 namespace opencog
00039 {
00040
00041 class Logger
00042 {
00043
00044 public:
00045
00046
00047
00048 enum Level { NONE, ERROR, WARN, INFO, DEBUG, FINE };
00049
00051 static const Level getLevelFromString(const std::string&);
00052 static const char* getLevelString(const Level);
00053
00054
00055
00056
00057 ~Logger();
00058
00066 Logger(const std::string &fileName = "opencog.log", Level level = INFO, bool timestampEnabled = true);
00067
00068 Logger(const Logger&);
00069
00070
00071
00072
00077 void setLevel(Level);
00078
00084 Level getLevel() const;
00085
00091 void setBackTraceLevel(Level);
00092
00097 Level getBackTraceLevel() const;
00098
00099
00100 void setFilename(const std::string&);
00101 const std::string& getFilename();
00102
00107 void setTimestampFlag(bool flag);
00108
00113 void setPrintToStdoutFlag(bool flag);
00114
00120 void setPrintErrorLevelStdout();
00121
00126 void log (Level level, const std::string &txt);
00127 void error(const std::string &txt);
00128 void warn (const std::string &txt);
00129 void info (const std::string &txt);
00130 void debug(const std::string &txt);
00131 void fine (const std::string &txt);
00132
00139 void logva(Level level, const char *, va_list args);
00140 void log (Level level, const char *, ...);
00141 void error(const char *, ...);
00142 void warn (const char *, ...);
00143 void info (const char *, ...);
00144 void debug(const char *, ...);
00145 void fine (const char *, ...);
00146
00152 bool isEnabled(Level level) const;
00153 bool isErrorEnabled() const;
00154 bool isWarnEnabled() const;
00155 bool isInfoEnabled() const;
00156 bool isDebugEnabled() const;
00157 bool isFineEnabled() const;
00158
00162 void enable();
00163
00167 void disable();
00168
00169 private:
00170
00171 std::string fileName;
00172 bool timestampEnabled;
00173 Level currentLevel;
00174 Level backTraceLevel;
00175 bool logEnabled;
00176 bool printToStdout;
00177 pthread_mutex_t lock;
00178 FILE *f;
00179
00180 };
00181
00182
00183 Logger& logger();
00184
00185 }
00186
00187 #endif // _OPENCOG_LOGGER_H