blocxx
|
00001 /******************************************************************************* 00002 * Copyright (C) 2005, Quest Software, Inc. All rights reserved. 00003 * Copyright (C) 2006, Novell, Inc. All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions are met: 00007 * 00008 * * Redistributions of source code must retain the above copyright notice, 00009 * this list of conditions and the following disclaimer. 00010 * * Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * * Neither the name of 00014 * Quest Software, Inc., 00015 * nor Novell, Inc., 00016 * nor the names of its contributors or employees may be used to 00017 * endorse or promote products derived from this software without 00018 * specific prior written permission. 00019 * 00020 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00021 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00022 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00023 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00024 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00025 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00026 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00027 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00028 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00029 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00030 * POSSIBILITY OF SUCH DAMAGE. 00031 *******************************************************************************/ 00032 00033 00038 #ifndef BLOCXX_LOG_APPENDER_IFC_HPP_INCLUDE_GUARD_ 00039 #define BLOCXX_LOG_APPENDER_IFC_HPP_INCLUDE_GUARD_ 00040 #include "blocxx/BLOCXX_config.h" 00041 #include "blocxx/CommonFwd.hpp" 00042 #include "blocxx/IntrusiveCountableBase.hpp" 00043 #include "blocxx/SortedVectorSet.hpp" 00044 #include "blocxx/LogConfig.hpp" 00045 #include "blocxx/LogMessagePatternFormatter.hpp" 00046 #include "blocxx/LazyGlobal.hpp" 00047 #include "blocxx/GlobalString.hpp" 00048 #include "blocxx/GlobalStringArray.hpp" 00049 #include "blocxx/String.hpp" 00050 00051 00052 namespace BLOCXX_NAMESPACE 00053 { 00054 00055 class BLOCXX_COMMON_API LogAppender : public IntrusiveCountableBase 00056 { 00057 public: 00058 00059 virtual ~LogAppender(); 00060 00070 static LogAppenderRef getCurrentLogAppender(); 00071 00078 static LogAppenderRef getDefaultLogAppender(); 00079 00084 static bool setDefaultLogAppender(const LogAppenderRef &ref); 00085 00091 static LogAppenderRef getThreadLogAppender(); 00092 00100 static bool setThreadLogAppender(const LogAppenderRef &ref); 00101 00106 void logMessage(const LogMessage& message) const; 00107 00108 bool categoryIsEnabled(const String& category) const; 00109 bool componentAndCategoryAreEnabled(const String& component, const String& category) const; 00110 00111 ELogLevel getLogLevel() const 00112 { 00113 return m_logLevel; 00114 } 00115 00144 static LogAppenderRef createLogAppender( 00145 const String& name, 00146 const StringArray& components, 00147 const StringArray& categories, 00148 const String& messageFormat, 00149 const String& type, 00150 const LoggerConfigMap& configItems); 00151 00153 static const GlobalStringArray ALL_COMPONENTS; 00155 static const GlobalStringArray ALL_CATEGORIES; 00158 static const GlobalString STR_TTCC_MESSAGE_FORMAT; 00160 static const GlobalString TYPE_SYSLOG; 00162 static const GlobalString TYPE_STDERR; 00164 static const GlobalString TYPE_FILE; 00166 static const GlobalString TYPE_MPFILE; 00168 static const GlobalString TYPE_NULL; 00169 00170 protected: 00171 00172 LogAppender(const StringArray& components = ALL_COMPONENTS, 00173 const StringArray& categories = ALL_CATEGORIES, 00174 const String& pattern = STR_TTCC_MESSAGE_FORMAT); 00175 00176 private: 00177 virtual void doProcessLogMessage(const String& formattedMessage, const LogMessage& message) const = 0; 00178 00179 private: // data 00180 SortedVectorSet<String> m_components; 00181 bool m_allComponents; 00182 SortedVectorSet<String> m_categories; 00183 bool m_allCategories; 00184 00185 LogMessagePatternFormatter m_formatter; 00186 00187 ELogLevel m_logLevel; 00188 00189 }; 00190 BLOCXX_EXPORT_TEMPLATE(BLOCXX_COMMON_API, IntrusiveReference, LogAppender); 00191 00192 #ifdef BLOCXX_WIN32 00193 extern DWORD dwTlsIndex; 00194 #else 00195 namespace 00196 { 00197 pthread_key_t g_loggerKey; 00198 } 00199 #endif 00200 00201 } // end namespace BLOCXX_NAMESPACE 00202 00203 #endif 00204 00205