OWBI1_Logger.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 * Copyright (C) 2003-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 #include "OWBI1_config.h"
00036 #include "OWBI1_Logger.hpp"
00037 #include "OW_ExceptionIds.hpp"
00038 #include "OWBI1_LogMessage.hpp"
00039 #include "OW_Assertion.hpp"
00040 #include "OWBI1_Array.hpp"
00041 #include "OW_Format.hpp"
00042 
00043 namespace OWBI1
00044 {
00045 
00046 OWBI1_DEFINE_EXCEPTION_WITH_ID(Logger);
00047 
00048 const String Logger::STR_NONE_CATEGORY("NONE");
00049 const String Logger::STR_FATAL_CATEGORY("FATAL");
00050 const String Logger::STR_ERROR_CATEGORY("ERROR");
00051 const String Logger::STR_INFO_CATEGORY("INFO");
00052 const String Logger::STR_DEBUG_CATEGORY("DEBUG");
00053 const String Logger::STR_ALL_CATEGORY("ALL");
00054 const String Logger::STR_DEFAULT_COMPONENT("none");
00055 
00057 Logger::~Logger()
00058 {
00059 }
00060 
00062 Logger::Logger(const String& defaultComponent, const ELogLevel l)
00063    : m_logLevel(l)
00064    , m_defaultComponent(defaultComponent)
00065 {
00066    OW_ASSERT(m_defaultComponent != "");
00067 }
00068 
00070 void
00071 Logger::processLogMessage(const LogMessage& message) const
00072 {
00073    OW_ASSERT(!message.component.empty());
00074    OW_ASSERT(!message.category.empty());
00075    OW_ASSERT(!message.message.empty());
00076 
00077    doProcessLogMessage(message);
00078 }
00079 
00081 void
00082 Logger::setLogLevel(const String& l)
00083 {
00084    if (l.equalsIgnoreCase(STR_INFO_CATEGORY))
00085    {
00086       setLogLevel(E_INFO_LEVEL);
00087    }
00088    else if (l.equalsIgnoreCase(STR_DEBUG_CATEGORY))
00089    {
00090       setLogLevel(E_DEBUG_LEVEL);
00091    }
00092    else if (l.equalsIgnoreCase(STR_ERROR_CATEGORY))
00093    {
00094       setLogLevel(E_ERROR_LEVEL);
00095    }
00096    else if (l.equalsIgnoreCase(STR_ALL_CATEGORY))
00097    {
00098       setLogLevel(E_ALL_LEVEL);
00099    }
00100    else if (l.equalsIgnoreCase(STR_NONE_CATEGORY))
00101    {
00102       setLogLevel(E_NONE_LEVEL);
00103    }
00104    else
00105    {
00106       setLogLevel(E_FATAL_ERROR_LEVEL);
00107    }
00108 }
00109 
00111 void
00112 Logger::logFatalError(const String& message, const char* filename, int fileline, const char* methodname) const
00113 {
00114    if (m_logLevel >= E_FATAL_ERROR_LEVEL)
00115    {
00116       processLogMessage( LogMessage(m_defaultComponent, STR_FATAL_CATEGORY, message, filename, fileline, methodname) );
00117    }
00118 }
00119 
00121 void
00122 Logger::logError(const String& message, const char* filename, int fileline, const char* methodname) const
00123 {
00124    if (m_logLevel >= E_ERROR_LEVEL)
00125    {
00126       processLogMessage( LogMessage(m_defaultComponent, STR_ERROR_CATEGORY, message, filename, fileline, methodname) );
00127    }
00128 }
00129 
00131 void
00132 Logger::logInfo(const String& message, const char* filename, int fileline, const char* methodname) const
00133 {
00134    if (m_logLevel >= E_INFO_LEVEL)
00135    {
00136       processLogMessage( LogMessage(m_defaultComponent, STR_INFO_CATEGORY, message, filename, fileline, methodname) );
00137    }
00138 }
00139 
00141 void
00142 Logger::logDebug(const String& message, const char* filename, int fileline, const char* methodname) const
00143 {
00144    if (m_logLevel >= E_DEBUG_LEVEL)
00145    {
00146       processLogMessage( LogMessage(m_defaultComponent, STR_DEBUG_CATEGORY, message, filename, fileline, methodname) );
00147    }
00148 }
00149    
00151 void
00152 Logger::logMessage(const String& component, const String& category, const String& message) const
00153 {
00154    processLogMessage(LogMessage(component, category, message, 0, -1, 0));
00155 }
00156 
00158 void
00159 Logger::logMessage(const String& component, const String& category, const String& message, const char* filename, int fileline, const char* methodname) const
00160 {
00161    processLogMessage(LogMessage(component, category, message, filename, fileline, methodname));
00162 }
00163 
00165 void
00166 Logger::logMessage(const String& category, const String& message) const
00167 {
00168    processLogMessage(LogMessage(m_defaultComponent, category, message, 0, -1, 0));
00169 }
00170 
00172 void
00173 Logger::logMessage(const String& category, const String& message, const char* filename, int fileline, const char* methodname) const
00174 {
00175    processLogMessage(LogMessage(m_defaultComponent, category, message, filename, fileline, methodname));
00176 }
00177 
00179 void
00180 Logger::logMessage(const LogMessage& message) const
00181 {
00182    processLogMessage(message);
00183 }
00184 
00186 bool
00187 Logger::categoryIsEnabled(const String& category) const
00188 {
00189    return doCategoryIsEnabled(category);
00190 }
00191 
00193 bool
00194 Logger::componentAndCategoryAreEnabled(const String& component, const String& category) const
00195 {
00196    return doComponentAndCategoryAreEnabled(component, category);
00197 }
00198 
00200 bool
00201 Logger::doComponentAndCategoryAreEnabled(const String& component, const String& category) const
00202 {
00203    return true;
00204 }
00205 
00207 bool
00208 Logger::doCategoryIsEnabled(const String& category) const
00209 {
00210    return true;
00211 }
00212 
00214 void
00215 Logger::setDefaultComponent(const String& component)
00216 {
00217    OW_ASSERT(component != "");
00218    m_defaultComponent = component;
00219 }
00220 
00222 String
00223 Logger::getDefaultComponent() const
00224 {
00225    return m_defaultComponent;
00226 }
00227    
00229 void
00230 Logger::setLogLevel(ELogLevel logLevel)
00231 {
00232    m_logLevel = logLevel;
00233 }
00234 
00236 LoggerRef
00237 Logger::clone() const
00238 {
00239    return doClone();
00240 }
00241 
00243 Logger::Logger(const Logger& x)
00244    : IntrusiveCountableBase(x)
00245    , m_logLevel(x.m_logLevel)
00246    , m_defaultComponent(x.m_defaultComponent)
00247 
00248 {
00249 }
00250 
00252 Logger&
00253 Logger::operator=(const Logger& x)
00254 {
00255    m_logLevel = x.m_logLevel;
00256    m_defaultComponent = x.m_defaultComponent;
00257    return *this;
00258 }
00259 
00261 void
00262 Logger::swap(Logger& x)
00263 {
00264    std::swap(m_logLevel, x.m_logLevel);
00265    m_defaultComponent.swap(x.m_defaultComponent);
00266 }
00267 
00268 
00269 } // end namespace OWBI1
00270 

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