00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
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:
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 }
00202
00203 #endif
00204
00205