00001
00002
00003 #ifndef BASE_LOG_H
00004 #define BASE_LOG_H
00005
00006 #include <cstdarg>
00007 #include "File.h"
00008 #include "Mutex.h"
00009 #include "Process.h"
00010
00011 namespace base {
00013
00017 class PPBASE_EXPORT Log: public Mutex {
00018 public:
00020 enum levels {
00021 FATAL = 1,
00022 ERR,
00023 WARNING,
00024 NOTICE,
00025 INFO,
00026 DEBUG
00027 };
00028
00030
00034 Log(const String &name, enum levels level = NOTICE);
00035
00037
00040 void debug(const char *func, const char *fmt, ...)
00041 #ifdef __GNUC__
00042 __attribute__((format(printf, 3, 4)))
00043 #endif
00044 ;
00045
00047
00050 void debug(const char *func, const String &msg);
00051
00053
00056 void error(const char *func, const char *fmt, ...)
00057 #ifdef __GNUC__
00058 __attribute__((format(printf, 3, 4)))
00059 #endif
00060 ;
00061
00063
00066 void error(const char *func, const String &msg);
00067
00069
00072 void error(const char *func, const Exception &ex);
00073
00075
00078 void fatal(const char *func, const char *fmt, ...)
00079 #ifdef __GNUC__
00080 __attribute__((format(printf, 3, 4)))
00081 #endif
00082 ;
00083
00085
00088 void fatal(const char *func, const String &msg);
00089
00091
00094 levels getLoglevel() const;
00095
00097
00100 String getLogfile();
00101
00103
00106 static const char *getLoglevelName(enum levels level);
00107
00109
00112 void info(const char *func, const char *fmt, ...)
00113 #ifdef __GNUC__
00114 __attribute__((format(printf, 3, 4)))
00115 #endif
00116 ;
00117
00119
00122 void info(const char *func, const String &msg);
00123
00125
00131 void vlog(enum levels level, const char *func, const char *fmt, va_list ap);
00132
00134
00140 void log(enum levels level, const char *func, const char *fmt, ...)
00141 #ifdef __GNUC__
00142 __attribute__((format(printf, 4, 5)))
00143 #endif
00144 ;
00145
00147
00152 void log(enum levels level, const char *func, const String &msg);
00153
00155
00158 void notice(const char *func, const char *fmt, ...)
00159 #ifdef __GNUC__
00160 __attribute__((format(printf, 3, 4)))
00161 #endif
00162 ;
00163
00165
00168 void notice(const char *func, const String &msg);
00169
00171
00174 void setLoglevel(enum levels level);
00175
00177
00180 void setPid(Process::pid_type pid = 0);
00181
00183
00186 void setStdErrLog(bool on = true);
00187
00189
00192 void warn(const char *func, const char *fmt, ...)
00193 #ifdef __GNUC__
00194 __attribute__((format(printf, 3, 4)))
00195 #endif
00196 ;
00197
00199
00202 void warn(const char *func, const String &msg);
00203
00204 private:
00206 void updateLogfileName();
00207
00208 File _file;
00209 int _log_lastday;
00210 String _logfile;
00211 bool _logfilecustom;
00212 enum levels _loglevel;
00213 Process::pid_type _pid;
00214 bool _stderr;
00215 DateTime _t;
00216 };
00217 }
00218
00219 #endif