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 OW_LOGGER_HPP_INCLUDE_GUARD_
00036 #define OW_LOGGER_HPP_INCLUDE_GUARD_
00037 #include "OW_config.h"
00038 #include "OW_CommonFwd.hpp"
00039 #include "OW_String.hpp"
00040 #include "OW_LogLevel.hpp"
00041 #include "OW_IntrusiveCountableBase.hpp"
00042 #include "OW_Exception.hpp"
00043 
00044 namespace OW_NAMESPACE
00045 {
00046 
00047 OW_DECLARE_APIEXCEPTION(Logger, OW_COMMON_API)
00048 
00049 
00050 
00074 class OW_COMMON_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 
00099    static LoggerRef getCurrentLogger();
00100 
00107    static LoggerRef getDefaultLogger();
00108 
00112    static bool setDefaultLogger(const LoggerRef &ref);
00113 
00117    static bool setThreadLogger(const LoggerRef &ref);
00118 
00126    void logFatalError(const String& message, const char* filename = 0, int fileline = -1, const char* methodname = 0) const;
00127    
00135    void logError(const String& message, const char* filename = 0, int fileline = -1, const char* methodname = 0) const;
00136    
00144    void logInfo(const String& message, const char* filename = 0, int fileline = -1, const char* methodname = 0) const;
00145    
00153    void logDebug(const String& message, const char* filename = 0, int fileline = -1, const char* methodname = 0) const;
00154 
00155    
00163    void logMessage(const String& component, const String& category, const String& message) const;
00174    void logMessage(const String& component, const String& category, const String& message, const char* filename, int fileline, const char* methodname) const;
00175 
00182    void logMessage(const String& category, const String& message) const;
00183    
00193    void logMessage(const String& category, const String& message, const char* filename, int fileline, const char* methodname) const;
00194 
00200    void logMessage(const LogMessage& message) const;
00201 
00207    void setDefaultComponent(const String& component);
00208 
00213    String getDefaultComponent() const;
00214 
00218    ELogLevel getLogLevel() const
00219    {
00220       return m_logLevel;
00221    }
00222 
00228    void setLogLevel(ELogLevel logLevel);
00229 
00237    void setLogLevel(const String& logLevel);
00238 
00242    bool categoryIsEnabled(const String& category) const;
00243 
00247    bool levelIsEnabled(const ELogLevel level);
00248 
00252    bool componentAndCategoryAreEnabled(const String& component, const String& category) const;
00253 
00262    LoggerRef clone() const;
00263 
00278    static LoggerRef createLogger( const String& type,
00279       bool debug ) OW_DEPRECATED;   
00280 
00281    virtual ~Logger();
00282 
00283 protected:
00284    Logger() OW_DEPRECATED; 
00285    Logger(const ELogLevel l) OW_DEPRECATED; 
00286 
00287    
00288 
00293    Logger(const String& defaultComponent, const ELogLevel logLevel);
00294 
00299    virtual void doProcessLogMessage(const LogMessage& message) const = 0;
00300 
00305    virtual bool doCategoryIsEnabled(const String& category) const;
00306    
00311    virtual bool doComponentAndCategoryAreEnabled(const String& component, const String& category) const;
00312 
00321    virtual LoggerRef doClone() const = 0;
00322 
00323 protected:
00324    Logger(const Logger&);
00325    Logger& operator=(const Logger&);
00326    void swap(Logger& x);
00327 
00328 private:
00329    void processLogMessage(const LogMessage& message) const;
00330 
00331 private: 
00332    ELogLevel m_logLevel;
00333    String m_defaultComponent;
00334 };
00335 OW_EXPORT_TEMPLATE(OW_COMMON_API, IntrusiveReference, Logger);
00336 
00337 } 
00338 
00339 
00340 #if defined(OW_HAVE_UUPRETTY_FUNCTIONUU)
00341 #define OW_LOGGER_PRETTY_FUNCTION __PRETTY_FUNCTION__
00342 #elif defined(OW_HAVE_C99_UUFUNCUU)
00343 #define OW_LOGGER_PRETTY_FUNCTION __func__
00344 #else
00345 #define OW_LOGGER_PRETTY_FUNCTION ""
00346 #endif
00347 
00354 #define OW_LOG_DEBUG(logger, message) \
00355 do \
00356 { \
00357    if ((logger)->getLogLevel() >= ::OW_NAMESPACE::E_DEBUG_LEVEL) \
00358    { \
00359       (logger)->logMessage(::OW_NAMESPACE::Logger::STR_DEBUG_CATEGORY, (message), __FILE__, __LINE__, OW_LOGGER_PRETTY_FUNCTION); \
00360    } \
00361 } while (0)
00362 
00369 #define OW_LOG_INFO(logger, message) \
00370 do \
00371 { \
00372    if ((logger)->getLogLevel() >= ::OW_NAMESPACE::E_INFO_LEVEL) \
00373    { \
00374       (logger)->logMessage(::OW_NAMESPACE::Logger::STR_INFO_CATEGORY, (message), __FILE__, __LINE__, OW_LOGGER_PRETTY_FUNCTION); \
00375    } \
00376 } while (0)
00377 
00384 #define OW_LOG_ERROR(logger, message) \
00385 do \
00386 { \
00387    if ((logger)->getLogLevel() >= ::OW_NAMESPACE::E_ERROR_LEVEL) \
00388    { \
00389       (logger)->logMessage(::OW_NAMESPACE::Logger::STR_ERROR_CATEGORY, (message), __FILE__, __LINE__, OW_LOGGER_PRETTY_FUNCTION); \
00390    } \
00391 } while (0)
00392 
00399 #define OW_LOG_FATAL_ERROR(logger, message) \
00400 do \
00401 { \
00402    if ((logger)->getLogLevel() >= ::OW_NAMESPACE::E_FATAL_ERROR_LEVEL) \
00403    { \
00404       (logger)->logMessage(::OW_NAMESPACE::Logger::STR_FATAL_CATEGORY, (message), __FILE__, __LINE__, OW_LOGGER_PRETTY_FUNCTION); \
00405    } \
00406 } while (0)
00407 
00415 #define OW_LOG(logger, category, message) \
00416 do \
00417 { \
00418    if ((logger)->categoryIsEnabled((category))) \
00419    { \
00420       (logger)->logMessage((category), (message), __FILE__, __LINE__, OW_LOGGER_PRETTY_FUNCTION); \
00421    } \
00422 } while (0)
00423 
00424 
00425 
00426 #endif