LogAppender.hpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 * Copyright (C) 2004 Vintela, Inc. All rights reserved.
00003 * Copyright (C) 2005 Novell, Inc. All rights reserved.
00004 *
00005 * Redistribution and use in source and binary forms, with or without
00006 * modification, are permitted provided that the following conditions are met:
00007 *
00008 *  - Redistributions of source code must retain the above copyright notice,
00009 *    this list of conditions and the following disclaimer.
00010 *
00011 *  - Redistributions in binary form must reproduce the above copyright notice,
00012 *    this list of conditions and the following disclaimer in the documentation
00013 *    and/or other materials provided with the distribution.
00014 *
00015 *  - Neither the name of Vintela, Inc., Novell, Inc., nor the names of its
00016 *    contributors may be used to endorse or promote products derived from this
00017 *    software without specific prior written permission.
00018 *
00019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00020 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00021 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00022 * ARE DISCLAIMED. IN NO EVENT SHALL Vintela, Inc., Novell, Inc., OR THE 
00023 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
00024 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
00025 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
00026 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
00027 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
00028 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
00029 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00030 *******************************************************************************/
00031 
00032 
00037 #ifndef BLOCXX_LOG_APPENDER_IFC_HPP_INCLUDE_GUARD_
00038 #define BLOCXX_LOG_APPENDER_IFC_HPP_INCLUDE_GUARD_
00039 #include "blocxx/BLOCXX_config.h"
00040 #include "blocxx/CommonFwd.hpp"
00041 #include "blocxx/IntrusiveCountableBase.hpp"
00042 #include "blocxx/SortedVectorSet.hpp"
00043 #include "blocxx/LogConfig.hpp"
00044 #include "blocxx/LogMessagePatternFormatter.hpp"
00045 
00046 
00047 // TODO make these go away .
00048 #ifndef BLOCXX_DEFAULT_LOG_1_MAX_FILE_SIZE
00049 #define BLOCXX_DEFAULT_LOG_1_MAX_FILE_SIZE "0"
00050 #endif
00051 #ifndef BLOCXX_DEFAULT_LOG_1_MAX_BACKUP_INDEX
00052 #define BLOCXX_DEFAULT_LOG_1_MAX_BACKUP_INDEX "1"
00053 #endif
00054 #ifndef BLOCXX_DEFAULT_LOG_1_FLUSH
00055 #define BLOCXX_DEFAULT_LOG_1_FLUSH "true"
00056 #endif
00057 #ifndef BLOCXX_DEFAULT_LOG_1_SYSLOG_IDENTITY
00058 #define BLOCXX_DEFAULT_LOG_1_SYSLOG_IDENTITY BLOCXX_PACKAGE_PREFIX"blocxx"
00059 #endif
00060 #ifndef BLOCXX_DEFAULT_LOG_1_SYSLOG_FACILITY
00061 #define BLOCXX_DEFAULT_LOG_1_SYSLOG_FACILITY "user"
00062 #endif
00063 
00064 namespace BLOCXX_NAMESPACE
00065 {
00066 
00067 #ifdef BLOCXX_WIN32
00068 template class BLOCXX_COMMON_API Array<String>;
00069 template class BLOCXX_COMMON_API SortedVectorSet<String>;
00070 #endif
00071 
00072 class BLOCXX_COMMON_API LogAppender : public IntrusiveCountableBase
00073 {
00074 public:
00075 
00076 // TODO make these go away .
00077    static const char* const LOG_1_LOCATION_opt; 
00078    static const char* const LOG_1_MAX_FILE_SIZE_opt; 
00079    static const char* const LOG_1_MAX_BACKUP_INDEX_opt; 
00080    static const char* const LOG_1_FLUSH_opt; 
00081    static const char* const LOG_1_SYSLOG_IDENTITY_opt;
00082    static const char* const LOG_1_SYSLOG_FACILITY_opt;
00083 
00084    virtual ~LogAppender();
00085 
00090    void logMessage(const LogMessage& message) const;
00091 
00092    bool categoryIsEnabled(const String& category) const;
00093    bool componentAndCategoryAreEnabled(const String& component, const String& category) const;
00094 
00095    ELogLevel getLogLevel() const;
00096 
00121    static LogAppenderRef createLogAppender(
00122       const String& name,
00123       const StringArray& components,
00124       const StringArray& categories,
00125       const String& messageFormat,
00126       const String& type,
00127       const LoggerConfigMap& configItems);
00128 
00130    static const StringArray ALL_COMPONENTS;
00132    static const StringArray ALL_CATEGORIES;
00135    static const String STR_TTCC_MESSAGE_FORMAT;
00137    static const String TYPE_SYSLOG;
00139    static const String TYPE_STDERR;
00141    static const String TYPE_FILE;
00143    static const String TYPE_NULL;
00144 
00145 protected:
00146 
00147    LogAppender(const StringArray& components, const StringArray& categories, const String& pattern);
00148 
00149 private:
00150    virtual void doProcessLogMessage(const String& formattedMessage, const LogMessage& message) const = 0;
00151 
00152 private: // data
00153    SortedVectorSet<String> m_components;
00154    bool m_allComponents;
00155    SortedVectorSet<String> m_categories;
00156    bool m_allCategories;
00157 
00158    LogMessagePatternFormatter m_formatter;
00159 
00160 };
00161 BLOCXX_EXPORT_TEMPLATE(BLOCXX_COMMON_API, IntrusiveReference, LogAppender);
00162 
00163 } // end namespace BLOCXX_NAMESPACE
00164 
00165 #endif
00166 
00167 

Generated on Fri Jun 16 15:39:08 2006 for blocxx by  doxygen 1.4.6