OW_AppenderLogger.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 * Copyright (C) 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 "OW_config.h"
00036 #include "OW_AppenderLogger.hpp"
00037 #include "OW_LogMessage.hpp"
00038 #include "OW_LogAppender.hpp"
00039 
00040 #ifdef OW_WIN32
00041 #include <algorithm>
00042 #endif
00043 
00044 namespace OW_NAMESPACE
00045 {
00046 
00048 AppenderLogger::AppenderLogger(const String& defaultComponent, ELogLevel level, const LogAppenderRef& appender)
00049    : Logger(defaultComponent, level)
00050    , m_appenders(1, appender)
00051 {
00052 }
00053 
00055 AppenderLogger::AppenderLogger(const String& defaultComponent, const Array<LogAppenderRef>& appenders)
00056    : Logger(defaultComponent, getLevel(appenders))
00057    , m_appenders(appenders)
00058 {
00059 }
00060 
00062 AppenderLogger::~AppenderLogger()
00063 {
00064 }
00065 
00067 void
00068 AppenderLogger::addLogAppender(const LogAppenderRef& appender)
00069 {
00070        m_appenders.append(appender);
00071 }
00072 
00074 void
00075 AppenderLogger::doProcessLogMessage(const LogMessage& message) const
00076 {
00077    for (size_t i = 0; i < m_appenders.size(); ++i)
00078    {
00079       m_appenders[i]->logMessage(message);
00080    }
00081 }
00082 
00084 bool
00085 AppenderLogger::doComponentAndCategoryAreEnabled(const String& component, const String& category) const
00086 {
00087    for (size_t i = 0; i < m_appenders.size(); ++i)
00088    {
00089       if (m_appenders[i]->componentAndCategoryAreEnabled(component, category))
00090       {
00091          return true;
00092       }
00093    }
00094    return false;
00095 }
00096 
00098 bool
00099 AppenderLogger::doCategoryIsEnabled(const String& category) const
00100 {
00101    for (size_t i = 0; i < m_appenders.size(); ++i)
00102    {
00103       if (m_appenders[i]->categoryIsEnabled(category))
00104       {
00105          return true;
00106       }
00107    }
00108    return false;
00109 }
00110 
00112 LoggerRef
00113 AppenderLogger::doClone() const
00114 {
00115    return LoggerRef(new AppenderLogger(*this));
00116 }
00117 
00119 #ifdef OW_WIN32
00120 using namespace std;
00121 #endif
00122 
00123 ELogLevel
00124 AppenderLogger::getLevel(const Array<LogAppenderRef>& appenders)
00125 {
00126    ELogLevel rv = E_FATAL_ERROR_LEVEL;
00127    for (size_t i = 0; i < appenders.size(); ++i)
00128    {
00129 #ifdef OW_WIN32
00130       // This format was necessary on windoz C2589
00131       rv = max(rv, appenders[i]->getLogLevel());
00132 #else
00133       rv = std::max(rv, appenders[i]->getLogLevel());
00134 #endif
00135    }
00136    return rv;
00137 }
00138 
00139 } // end namespace OW_NAMESPACE
00140 
00141 
00142 
00143 
00144 
00145 

Generated on Thu Feb 9 08:47:49 2006 for openwbem by  doxygen 1.4.6