00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00018 #ifndef _LO4CPLUS_NDC_HEADER_
00019 #define _LO4CPLUS_NDC_HEADER_
00020
00021 #include <log4cplus/config.h>
00022 #include <log4cplus/tstring.h>
00023 #include <log4cplus/helpers/logloguser.h>
00024 #include <log4cplus/helpers/threads.h>
00025
00026 #include <map>
00027 #include <stack>
00028
00029 #if (defined(__MWERKS__) && defined(__MACOS__))
00030 using std::size_t;
00031 #endif
00032
00033
00034 namespace log4cplus {
00035
00036 class NDC;
00037 struct DiagnosticContext;
00038 typedef std::stack<DiagnosticContext> DiagnosticContextStack;
00039
00043 LOG4CPLUS_EXPORT NDC& getNDC();
00044
00109 class LOG4CPLUS_EXPORT NDC : protected log4cplus::helpers::LogLogUser {
00110 public:
00119 void clear();
00120
00134 DiagnosticContextStack cloneStack();
00135
00150 void inherit(const DiagnosticContextStack& stack);
00151
00155 log4cplus::tstring get();
00156
00162 size_t getDepth();
00163
00175 log4cplus::tstring pop();
00176
00186 log4cplus::tstring peek();
00187
00198 void push(const log4cplus::tstring& message);
00199
00207 void remove();
00208
00239 void setMaxDepth(size_t maxDepth);
00240
00241
00242 ~NDC();
00243
00244 private:
00245
00246 DiagnosticContextStack* getPtr()
00247 { return static_cast<DiagnosticContextStack*>
00248 (LOG4CPLUS_GET_THREAD_LOCAL_VALUE( threadLocal )); }
00249
00250
00251 LOG4CPLUS_THREAD_LOCAL_TYPE threadLocal;
00252
00253
00254 NDC();
00255 NDC(const NDC&);
00256 NDC& operator=(const NDC&);
00257
00258
00259 friend LOG4CPLUS_EXPORT NDC& getNDC();
00260 };
00261
00262
00263
00267 struct LOG4CPLUS_EXPORT DiagnosticContext {
00268
00269 DiagnosticContext(const log4cplus::tstring& message, DiagnosticContext *parent);
00270 DiagnosticContext(const log4cplus::tstring& message);
00271
00272
00273 log4cplus::tstring message;
00274 log4cplus::tstring fullMessage;
00275 };
00276
00277
00282 class LOG4CPLUS_EXPORT NDCContextCreator {
00283 public:
00285 NDCContextCreator(const log4cplus::tstring& msg) { getNDC().push(msg); }
00286
00288 ~NDCContextCreator() { getNDC().pop(); }
00289 };
00290
00291 }
00292
00293
00294 #endif // _LO4CPLUS_NDC_HEADER_