00001
00033 #ifndef LL_LLERROR_H
00034 #define LL_LLERROR_H
00035
00036 #include <sstream>
00037 #include <typeinfo>
00038
00039 #include "llerrorlegacy.h"
00040
00041
00042
00043
00044
00045
00046
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
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108 namespace LLError
00109 {
00110 enum ELevel
00111 {
00112 LEVEL_ALL = 0,
00113
00114
00115 LEVEL_DEBUG = 0,
00116 LEVEL_INFO = 1,
00117 LEVEL_WARN = 2,
00118 LEVEL_ERROR = 3,
00119
00120 LEVEL_NONE = 4
00121
00122
00123 };
00124
00125
00126
00127
00128
00129
00130 class CallSite;
00131
00132 class Log
00133 {
00134 public:
00135 static bool shouldLog(CallSite&);
00136 static std::ostringstream* out();
00137 static void flush(std::ostringstream*, const CallSite&);
00138 };
00139
00140 class CallSite
00141 {
00142
00143
00144
00145 public:
00146 CallSite(ELevel, const char* file, int line,
00147 const std::type_info& class_info, const char* function, const char* broadTag, const char* narrowTag, bool printOnce);
00148
00149 bool shouldLog()
00150 { return mCached ? mShouldLog : Log::shouldLog(*this); }
00151
00152
00153 void invalidate();
00154
00155 private:
00156
00157 const ELevel mLevel;
00158 const char* const mFile;
00159 const int mLine;
00160 const std::type_info& mClassInfo;
00161 const char* const mFunction;
00162 const char* const mBroadTag;
00163 const char* const mNarrowTag;
00164 const bool mPrintOnce;
00165
00166
00167 bool mCached;
00168 bool mShouldLog;
00169
00170 friend class Log;
00171 };
00172
00173
00174 class End { };
00175 inline std::ostream& operator<<(std::ostream& s, const End&)
00176 { return s; }
00177
00178
00179 class NoClassInfo { };
00180
00181 }
00182
00183
00184
00185
00186
00187
00188
00189 #define LOG_CLASS(s) typedef s _LL_CLASS_TO_LOG
00190
00191
00192
00193 typedef LLError::NoClassInfo _LL_CLASS_TO_LOG;
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206 #define lllog(level, broadTag, narrowTag, once) \
00207 { \
00208 static LLError::CallSite _site( \
00209 level, __FILE__, __LINE__, typeid(_LL_CLASS_TO_LOG), __FUNCTION__, broadTag, narrowTag, once);\
00210 if (_site.shouldLog()) \
00211 { \
00212 std::ostringstream* _out = LLError::Log::out(); \
00213 (*_out)
00214
00215
00216 #define llendl \
00217 LLError::End(); \
00218 LLError::Log::flush(_out, _site); \
00219 } \
00220 }
00221
00222
00223 #define lldebugs lllog(LLError::LEVEL_DEBUG, NULL, NULL, false)
00224 #define llinfos lllog(LLError::LEVEL_INFO, NULL, NULL, false)
00225 #define llwarns lllog(LLError::LEVEL_WARN, NULL, NULL, false)
00226 #define llerrs lllog(LLError::LEVEL_ERROR, NULL, NULL, false)
00227 #define llcont (*_out)
00228
00229
00230
00231
00232 #define LL_DEBUGS(broadTag) lllog(LLError::LEVEL_DEBUG, broadTag, NULL, false)
00233 #define LL_INFOS(broadTag) lllog(LLError::LEVEL_INFO, broadTag, NULL, false)
00234 #define LL_WARNS(broadTag) lllog(LLError::LEVEL_WARN, broadTag, NULL, false)
00235 #define LL_ERRS(broadTag) lllog(LLError::LEVEL_ERROR, broadTag, NULL, false)
00236
00237 #define LL_DEBUGS2(broadTag, narrowTag) lllog(LLError::LEVEL_DEBUG, broadTag, narrowTag, false)
00238 #define LL_INFOS2(broadTag, narrowTag) lllog(LLError::LEVEL_INFO, broadTag, narrowTag, false)
00239 #define LL_WARNS2(broadTag, narrowTag) lllog(LLError::LEVEL_WARN, broadTag, narrowTag, false)
00240 #define LL_ERRS2(broadTag, narrowTag) lllog(LLError::LEVEL_ERROR, broadTag, narrowTag, false)
00241
00242
00243
00244 #define LL_DEBUGS_ONCE(broadTag) lllog(LLError::LEVEL_DEBUG, broadTag, NULL, true)
00245 #define LL_INFOS_ONCE(broadTag) lllog(LLError::LEVEL_INFO, broadTag, NULL, true)
00246 #define LL_WARNS_ONCE(broadTag) lllog(LLError::LEVEL_WARN, broadTag, NULL, true)
00247 #define LL_DEBUGS2_ONCE(broadTag, narrowTag) lllog(LLError::LEVEL_DEBUG, broadTag, narrowTag, true)
00248 #define LL_INFOS2_ONCE(broadTag, narrowTag) lllog(LLError::LEVEL_INFO, broadTag, narrowTag, true)
00249 #define LL_WARNS2_ONCE(broadTag, narrowTag) lllog(LLError::LEVEL_WARN, broadTag, narrowTag, true)
00250
00251 #define LL_ENDL llendl
00252 #define LL_CONT (*_out)
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271 #endif // LL_LLERROR_H