00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef CLOG_H
00016 #define CLOG_H
00017
00018 #include "common.h"
00019 #include "IArchMultithread.h"
00020 #include "stdlist.h"
00021 #include <stdarg.h>
00022
00023 #define CLOG (CLog::getInstance())
00024
00025 class ILogOutputter;
00026
00028
00034 class CLog {
00035 public:
00037
00040 enum ELevel {
00041 kFATAL,
00042 kERROR,
00043 kWARNING,
00044 kNOTE,
00045 kINFO,
00046 kDEBUG,
00047 kDEBUG1,
00048 kDEBUG2
00049 };
00050
00051 ~CLog();
00052
00054
00055
00057
00071 void insert(ILogOutputter* adopted,
00072 bool alwaysAtHead = false);
00073
00075
00080 void remove(ILogOutputter* orphaned);
00081
00083
00088 void pop_front(bool alwaysAtHead = false);
00089
00091
00098 bool setFilter(const char* name);
00099 void setFilter(int);
00100
00102
00103
00104
00106
00111 void print(const char* file, int line,
00112 const char* format, ...) const;
00113
00115 int getFilter() const;
00116
00118 static CLog* getInstance();
00119
00121
00122 private:
00123 CLog();
00124
00125 void output(int priority, char* msg) const;
00126
00127 private:
00128 typedef std::list<ILogOutputter*> COutputterList;
00129
00130 static CLog* s_log;
00131
00132 CArchMutex m_mutex;
00133 COutputterList m_outputters;
00134 COutputterList m_alwaysOutputters;
00135 int m_maxNewlineLength;
00136 int m_maxPriority;
00137 };
00138
00178 #if defined(NOLOGGING)
00179 #define LOG(_a1)
00180 #define LOGC(_a1, _a2)
00181 #define CLOG_TRACE
00182 #elif defined(NDEBUG)
00183 #define LOG(_a1) CLOG->print _a1
00184 #define LOGC(_a1, _a2) if (_a1) CLOG->print _a2
00185 #define CLOG_TRACE NULL, 0,
00186 #else
00187 #define LOG(_a1) CLOG->print _a1
00188 #define LOGC(_a1, _a2) if (_a1) CLOG->print _a2
00189 #define CLOG_TRACE __FILE__, __LINE__,
00190 #endif
00191
00192 #define CLOG_PRINT CLOG_TRACE "%z\057"
00193 #define CLOG_CRIT CLOG_TRACE "%z\060"
00194 #define CLOG_ERR CLOG_TRACE "%z\061"
00195 #define CLOG_WARN CLOG_TRACE "%z\062"
00196 #define CLOG_NOTE CLOG_TRACE "%z\063"
00197 #define CLOG_INFO CLOG_TRACE "%z\064"
00198 #define CLOG_DEBUG CLOG_TRACE "%z\065"
00199 #define CLOG_DEBUG1 CLOG_TRACE "%z\066"
00200 #define CLOG_DEBUG2 CLOG_TRACE "%z\067"
00201
00202 #endif