log4cplus
1.1.0
|
00001 // -*- C++ -*- 00002 // Copyright (C) 2010, Vaclav Haisman. All rights reserved. 00003 // 00004 // Redistribution and use in source and binary forms, with or without modifica- 00005 // tion, are permitted provided that the following conditions are met: 00006 // 00007 // 1. Redistributions of source code must retain the above copyright notice, 00008 // this list of conditions and the following disclaimer. 00009 // 00010 // 2. Redistributions in binary form must reproduce the above copyright notice, 00011 // this list of conditions and the following disclaimer in the documentation 00012 // and/or other materials provided with the distribution. 00013 // 00014 // THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 00015 // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 00016 // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00017 // APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 00018 // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- 00019 // DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 00020 // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 00021 // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00022 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 00023 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00024 00025 #ifndef LOG4CPLUS_MDC_H_HEADER 00026 #define LOG4CPLUS_MDC_H_HEADER 00027 00028 #include <log4cplus/config.hxx> 00029 00030 #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE) 00031 #pragma once 00032 #endif 00033 00034 #include <log4cplus/tstring.h> 00035 00036 #include <map> 00037 00038 00039 namespace log4cplus 00040 { 00041 00042 00043 typedef std::map<tstring, tstring> MappedDiagnosticContextMap; 00044 00045 00046 class LOG4CPLUS_EXPORT MDC 00047 { 00048 public: 00054 void clear(); 00055 00056 void put (tstring const & key, tstring const & value); 00057 bool get (tstring * value, tstring const & key) const; 00058 void remove (tstring const & key); 00059 00060 MappedDiagnosticContextMap const & getContext () const; 00061 00062 // Public ctor and dtor but only to be used by internal::DefaultContext. 00063 MDC (); 00064 virtual ~MDC (); 00065 00066 private: 00067 LOG4CPLUS_PRIVATE static MappedDiagnosticContextMap * getPtr (); 00068 }; 00069 00070 00071 LOG4CPLUS_EXPORT MDC & getMDC (); 00072 00073 00074 } // namespace log4cplus 00075 00076 00077 #endif // LOG4CPLUS_MDC_H_HEADER