OW_Logger.hpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 * Copyright (C) 2001-2004 Vintela, Inc. All rights reserved.
00003 *
00004 * Redistribution and use in source and binary forms, with or without
00005 * modification, are permitted provided that the following conditions are met:
00006 *
00007 *  - Redistributions of source code must retain the above copyright notice,
00008 *    this list of conditions and the following disclaimer.
00009 *
00010 *  - 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 *  - Neither the name of Vintela, Inc. nor the names of its
00015 *    contributors may be used to endorse or promote products derived from this
00016 *    software without specific prior written permission.
00017 *
00018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00019 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 * ARE DISCLAIMED. IN NO EVENT SHALL Vintela, Inc. OR THE CONTRIBUTORS
00022 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00023 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00024 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00025 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00026 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00027 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00028 * POSSIBILITY OF SUCH DAMAGE.
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; // "none"
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    // Note that we don't use defaults on logMessage so the correct overload will be chosen.
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;   // in 3.1.0
00280 
00281    virtual ~Logger();
00282 
00283 protected:
00284    Logger() OW_DEPRECATED; // in 3.1.0
00285    Logger(const ELogLevel l) OW_DEPRECATED; // in 3.1.0
00286 
00287    // Derived class interface
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: // data
00332    ELogLevel m_logLevel;
00333    String m_defaultComponent;
00334 };
00335 OW_EXPORT_TEMPLATE(OW_COMMON_API, IntrusiveReference, Logger);
00336 
00337 } // end namespace OW_NAMESPACE
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

Generated on Thu Feb 9 08:48:03 2006 for openwbem by  doxygen 1.4.6