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
00035 #ifndef OWBI1_LOGGER_HPP_INCLUDE_GUARD_
00036 #define OWBI1_LOGGER_HPP_INCLUDE_GUARD_
00037 #include "OWBI1_config.h"
00038 #include "OWBI1_CommonFwd.hpp"
00039 #include "OWBI1_String.hpp"
00040 #include "OWBI1_LogLevel.hpp"
00041 #include "OWBI1_IntrusiveCountableBase.hpp"
00042 #include "OWBI1_Exception.hpp"
00043
00044 namespace OWBI1
00045 {
00046
00047 OWBI1_DECLARE_APIEXCEPTION(Logger, OWBI1_COMMON_API)
00048
00049
00050
00074 class OWBI1_OWBI1PROVIFC_API Logger : public IntrusiveCountableBase
00075 {
00076 public:
00077
00078 static const String STR_NONE_CATEGORY;
00079 static const String STR_FATAL_CATEGORY;
00080 static const String STR_ERROR_CATEGORY;
00081 static const String STR_INFO_CATEGORY;
00082 static const String STR_DEBUG_CATEGORY;
00083 static const String STR_ALL_CATEGORY;
00084 static const String STR_DEFAULT_COMPONENT;
00085
00086 enum ELoggerErrorCodes
00087 {
00088 E_UNKNOWN_LOG_APPENDER_TYPE,
00089 E_INVALID_MAX_FILE_SIZE,
00090 E_INVALID_MAX_BACKUP_INDEX
00091 };
00092
00100 void logFatalError(const String& message, const char* filename = 0, int fileline = -1, const char* methodname = 0) const;
00101
00109 void logError(const String& message, const char* filename = 0, int fileline = -1, const char* methodname = 0) const;
00110
00118 void logInfo(const String& message, const char* filename = 0, int fileline = -1, const char* methodname = 0) const;
00119
00127 void logDebug(const String& message, const char* filename = 0, int fileline = -1, const char* methodname = 0) const;
00128
00129
00137 void logMessage(const String& component, const String& category, const String& message) const;
00148 void logMessage(const String& component, const String& category, const String& message, const char* filename, int fileline, const char* methodname) const;
00149
00156 void logMessage(const String& category, const String& message) const;
00157
00167 void logMessage(const String& category, const String& message, const char* filename, int fileline, const char* methodname) const;
00168
00174 void logMessage(const LogMessage& message) const;
00175
00181 void setDefaultComponent(const String& component);
00182
00187 String getDefaultComponent() const;
00188
00192 ELogLevel getLogLevel() const
00193 {
00194 return m_logLevel;
00195 }
00196
00202 void setLogLevel(ELogLevel logLevel);
00203
00211 void setLogLevel(const String& logLevel);
00212
00216 bool categoryIsEnabled(const String& category) const;
00217
00221 bool componentAndCategoryAreEnabled(const String& component, const String& category) const;
00222
00231 LoggerRef clone() const;
00232
00233 virtual ~Logger();
00234
00235 protected:
00236
00237
00242 Logger(const String& defaultComponent, const ELogLevel logLevel);
00243
00248 virtual void doProcessLogMessage(const LogMessage& message) const = 0;
00249
00254 virtual bool doCategoryIsEnabled(const String& category) const;
00255
00260 virtual bool doComponentAndCategoryAreEnabled(const String& component, const String& category) const;
00261
00270 virtual LoggerRef doClone() const = 0;
00271
00272 protected:
00273 Logger(const Logger&);
00274 Logger& operator=(const Logger&);
00275 void swap(Logger& x);
00276
00277 private:
00278 void processLogMessage(const LogMessage& message) const;
00279
00280 private:
00281 ELogLevel m_logLevel;
00282 String m_defaultComponent;
00283 };
00284
00285 }
00286
00287
00288 #if defined(OWBI1_HAVE_UUPRETTY_FUNCTIONUU)
00289 #define OWBI1_LOGGER_PRETTY_FUNCTION __PRETTY_FUNCTION__
00290 #elif defined(OWBI1_HAVE_C99_UUFUNCUU)
00291 #define OWBI1_LOGGER_PRETTY_FUNCTION __func__
00292 #else
00293 #define OWBI1_LOGGER_PRETTY_FUNCTION ""
00294 #endif
00295
00302 #define OWBI1_LOG_DEBUG(logger, message) \
00303 do \
00304 { \
00305 if ((logger)->getLogLevel() >= ::OWBI1::E_DEBUG_LEVEL) \
00306 { \
00307 (logger)->logMessage(::OWBI1::Logger::STR_DEBUG_CATEGORY, (message), __FILE__, __LINE__, OWBI1_LOGGER_PRETTY_FUNCTION); \
00308 } \
00309 } while (0)
00310
00317 #define OWBI1_LOG_INFO(logger, message) \
00318 do \
00319 { \
00320 if ((logger)->getLogLevel() >= ::OWBI1::E_INFO_LEVEL) \
00321 { \
00322 (logger)->logMessage(::OWBI1::Logger::STR_INFO_CATEGORY, (message), __FILE__, __LINE__, OWBI1_LOGGER_PRETTY_FUNCTION); \
00323 } \
00324 } while (0)
00325
00332 #define OWBI1_LOG_ERROR(logger, message) \
00333 do \
00334 { \
00335 if ((logger)->getLogLevel() >= ::OWBI1::E_ERROR_LEVEL) \
00336 { \
00337 (logger)->logMessage(::OWBI1::Logger::STR_ERROR_CATEGORY, (message), __FILE__, __LINE__, OWBI1_LOGGER_PRETTY_FUNCTION); \
00338 } \
00339 } while (0)
00340
00347 #define OWBI1_LOG_FATAL_ERROR(logger, message) \
00348 do \
00349 { \
00350 if ((logger)->getLogLevel() >= ::OWBI1::E_FATAL_ERROR_LEVEL) \
00351 { \
00352 (logger)->logMessage(::OWBI1::Logger::STR_FATAL_CATEGORY, (message), __FILE__, __LINE__, OWBI1_LOGGER_PRETTY_FUNCTION); \
00353 } \
00354 } while (0)
00355
00363 #define OWBI1_LOG(logger, category, message) \
00364 do \
00365 { \
00366 if ((logger)->categoryIsEnabled((category))) \
00367 { \
00368 (logger)->logMessage((category), (message), __FILE__, __LINE__, OWBI1_LOGGER_PRETTY_FUNCTION); \
00369 } \
00370 } while (0)
00371
00372
00373
00374 #endif