OWBI1_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 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; // "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 
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    // Note that we don't use defaults on logMessage so the correct overload will be chosen.
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    // Derived class interface
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: // data
00281    ELogLevel m_logLevel;
00282    String m_defaultComponent;
00283 };
00284 
00285 } // end namespace OWBI1
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

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