blocxx
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Private Member Functions | Private Attributes

BLOCXX_NAMESPACE::LogAppender Class Reference

#include <LogAppender.hpp>

Inheritance diagram for BLOCXX_NAMESPACE::LogAppender:
BLOCXX_NAMESPACE::IntrusiveCountableBase BLOCXX_NAMESPACE::CerrAppender BLOCXX_NAMESPACE::FileAppender BLOCXX_NAMESPACE::MultiAppender BLOCXX_NAMESPACE::MultiProcessFileAppender BLOCXX_NAMESPACE::NullAppender BLOCXX_NAMESPACE::SyslogAppender

List of all members.

Public Member Functions

virtual ~LogAppender ()
void logMessage (const LogMessage &message) const
 Log a message using the specified component and category.
bool categoryIsEnabled (const String &category) const
bool componentAndCategoryAreEnabled (const String &component, const String &category) const
ELogLevel getLogLevel () const

Static Public Member Functions

static LogAppenderRef getCurrentLogAppender ()
 Get a copy of the per thread LogAppenderRef or if not set, the default one.
static LogAppenderRef getDefaultLogAppender ()
 Returns a copy of default LogAppenderRef.
static bool setDefaultLogAppender (const LogAppenderRef &ref)
 Set the default global LogAppenderRef.
static LogAppenderRef getThreadLogAppender ()
 Returns a copy of the thread LogAppenderRef.
static bool setThreadLogAppender (const LogAppenderRef &ref)
 Set a per thread LogAppenderRef that overrides the default one.
static LogAppenderRef createLogAppender (const String &name, const StringArray &components, const StringArray &categories, const String &messageFormat, const String &type, const LoggerConfigMap &configItems)
 Create a concrete log appender depending on the type string passed in.

Static Public Attributes

static const GlobalStringArray ALL_COMPONENTS = BLOCXX_GLOBAL_STRING_INIT("*")
 Pass to createLogAppender to indicate all components.
static const GlobalStringArray ALL_CATEGORIES = BLOCXX_GLOBAL_STRING_INIT("*")
 Pass to createLogAppender to indicate all categories.
static const GlobalString STR_TTCC_MESSAGE_FORMAT = BLOCXX_GLOBAL_STRING_INIT("%r [%t] %-5p %c - %m")
 The Log4j TTCC message format - TTCC is acronym for Time Thread Category Component.
static const GlobalString TYPE_SYSLOG = BLOCXX_GLOBAL_STRING_INIT("syslog")
 String of the type of the syslog log appender.
static const GlobalString TYPE_STDERR = BLOCXX_GLOBAL_STRING_INIT("stderr")
 String of the type of the stderr log appender.
static const GlobalString TYPE_FILE = BLOCXX_GLOBAL_STRING_INIT("file")
 String of the type of the file log appender.
static const GlobalString TYPE_MPFILE = BLOCXX_GLOBAL_STRING_INIT("mpfile")
 String of the type of the multi-process file log appender.
static const GlobalString TYPE_NULL = BLOCXX_GLOBAL_STRING_INIT("null")
 String of the type of the null log appender.

Protected Member Functions

 LogAppender (const StringArray &components=ALL_COMPONENTS, const StringArray &categories=ALL_CATEGORIES, const String &pattern=STR_TTCC_MESSAGE_FORMAT)

Private Member Functions

virtual void doProcessLogMessage (const String &formattedMessage, const LogMessage &message) const =0

Private Attributes

SortedVectorSet< Stringm_components
bool m_allComponents
SortedVectorSet< Stringm_categories
bool m_allCategories
LogMessagePatternFormatter m_formatter
ELogLevel m_logLevel

Detailed Description

Definition at line 55 of file LogAppender.hpp.


Constructor & Destructor Documentation

BLOCXX_NAMESPACE::LogAppender::~LogAppender ( ) [virtual]

Definition at line 83 of file LogAppender.cpp.

BLOCXX_NAMESPACE::LogAppender::LogAppender ( const StringArray components = ALL_COMPONENTS,
const StringArray categories = ALL_CATEGORIES,
const String pattern = STR_TTCC_MESSAGE_FORMAT 
) [protected]

Member Function Documentation

bool BLOCXX_NAMESPACE::LogAppender::categoryIsEnabled ( const String category) const
bool BLOCXX_NAMESPACE::LogAppender::componentAndCategoryAreEnabled ( const String component,
const String category 
) const

Definition at line 282 of file LogAppender.cpp.

LogAppenderRef BLOCXX_NAMESPACE::LogAppender::createLogAppender ( const String name,
const StringArray components,
const StringArray categories,
const String messageFormat,
const String type,
const LoggerConfigMap configItems 
) [static]

Create a concrete log appender depending on the type string passed in.

If type == "syslog" (TYPE_SYSLOG) a logger the writes to the syslog will be returned. If type == "" || type == "null" (TYPE_NULL) a logger that doesn't do anything will be returned. If type == "cerr" || type == "stderr" (TYPE_STDERR) a logger that writes to stderr will be returned. If type == "file" (TYPE_FILE) then a logger that writes to a file -- will be returned; the file name and other parameters are taken from configItems. If type == "mpfile" (TYPE_MPFILE) then a logger that writes to a file that may be shared with other process will be returned; the file name and other parameters are taken from configItems.

Parameters:
nameThe name of the logger to create
componentsThe message components the logger will log. "*" means all components.
categoriesThe message categories the logger will log. "*" means all categories.
typeThe type of logger to create
configItemsAdditional config items the logger may use for configuration.
Returns:
a class that implements the Logger interface.
Exceptions:
LoggerException- E_UNKNOWN_LOG_APPENDER_TYPE - if type is unkonwn.

  • E_INVALID_MAX_FILE_SIZE - if the max_file_size option is invalid
  • E_INVALID_MAX_BACKUP_INDEX - if the max_backup_index option is invalid

Definition at line 308 of file LogAppender.cpp.

References BLOCXX_DEFAULT_LOG_1_FLUSH, BLOCXX_DEFAULT_LOG_1_MAX_BACKUP_INDEX, BLOCXX_DEFAULT_LOG_1_MAX_FILE_SIZE, BLOCXX_DEFAULT_LOG_1_SYSLOG_FACILITY, BLOCXX_DEFAULT_LOG_1_SYSLOG_IDENTITY, BLOCXX_THROW_ERR, BLOCXX_THROW_ERR_SUBEX, BLOCXX_NAMESPACE::String::c_str(), BLOCXX_NAMESPACE::Logger::E_INVALID_MAX_BACKUP_INDEX, BLOCXX_NAMESPACE::Logger::E_INVALID_MAX_FILE_SIZE, BLOCXX_NAMESPACE::Logger::E_UNKNOWN_LOG_APPENDER_TYPE, BLOCXX_NAMESPACE::String::empty(), BLOCXX_NAMESPACE::String::equalsIgnoreCase(), BLOCXX_NAMESPACE::Exception::getMessage(), BLOCXX_NAMESPACE::LogConfigOptions::LOG_1_FLUSH_opt, BLOCXX_NAMESPACE::LogConfigOptions::LOG_1_LOCATION_opt, BLOCXX_NAMESPACE::LogConfigOptions::LOG_1_MAX_BACKUP_INDEX_opt, BLOCXX_NAMESPACE::LogConfigOptions::LOG_1_MAX_FILE_SIZE_opt, BLOCXX_NAMESPACE::LogConfigOptions::LOG_1_SYSLOG_FACILITY_opt, BLOCXX_NAMESPACE::LogConfigOptions::LOG_1_SYSLOG_IDENTITY_opt, TYPE_FILE, TYPE_MPFILE, TYPE_NULL, TYPE_STDERR, and TYPE_SYSLOG.

virtual void BLOCXX_NAMESPACE::LogAppender::doProcessLogMessage ( const String formattedMessage,
const LogMessage message 
) const [private, pure virtual]
LogAppenderRef BLOCXX_NAMESPACE::LogAppender::getCurrentLogAppender ( ) [static]

Get a copy of the per thread LogAppenderRef or if not set, the default one.

If neither setDefaultLogAppender() or setThreadLogAppender() has been called, the default LogAppender will be set to a NullAppender, and then returned.

This method is preferred over getDefaultLogAppender() or getThreadLogAppender().

Definition at line 137 of file LogAppender.cpp.

LogAppenderRef BLOCXX_NAMESPACE::LogAppender::getDefaultLogAppender ( ) [static]

Returns a copy of default LogAppenderRef.

If you want to get a log appender to log messages, you shouldn't call this function. Use getCurrentLogAppender() instead. If setDefaultLogAppender() hasn't been called, the default LogAppender will be set to a NullAppender, and then returned.

Definition at line 153 of file LogAppender.cpp.

ELogLevel BLOCXX_NAMESPACE::LogAppender::getLogLevel ( ) const [inline]

Definition at line 111 of file LogAppender.hpp.

LogAppenderRef BLOCXX_NAMESPACE::LogAppender::getThreadLogAppender ( ) [static]

Returns a copy of the thread LogAppenderRef.

If you want to get a log appender to log messages, you shouldn't call this function. Use getCurrentLogAppender() instead. If setThreadLogAppender() hasn't been called by the current thread, a null LogAppenderRef is returned.

Definition at line 185 of file LogAppender.cpp.

void BLOCXX_NAMESPACE::LogAppender::logMessage ( const LogMessage message) const

Log a message using the specified component and category.

Parameters:
messageThe message to log

Definition at line 263 of file LogAppender.cpp.

bool BLOCXX_NAMESPACE::LogAppender::setDefaultLogAppender ( const LogAppenderRef ref) [static]

Set the default global LogAppenderRef.

Each application that wants logging should call this function with the desired LogAppenderRef.

Definition at line 168 of file LogAppender.cpp.

bool BLOCXX_NAMESPACE::LogAppender::setThreadLogAppender ( const LogAppenderRef ref) [static]

Set a per thread LogAppenderRef that overrides the default one.

If a thread desires to use a different log appender than the default, it can call this function to set it.

Parameters:
refThe appender that will be returned from subsequent calls to getCurrentLogAppender() or getThreadLogAppender() by the same thread. Pass a null to cause subsequent calls to getCurrentLogAppender() to return the global LogAppenderRef.

Definition at line 216 of file LogAppender.cpp.

Referenced by BLOCXX_NAMESPACE::LogAppenderScope::LogAppenderScope(), and BLOCXX_NAMESPACE::LogAppenderScope::~LogAppenderScope().


Member Data Documentation

const GlobalStringArray BLOCXX_NAMESPACE::LogAppender::ALL_CATEGORIES = BLOCXX_GLOBAL_STRING_INIT("*") [static]

Pass to createLogAppender to indicate all categories.

Definition at line 155 of file LogAppender.hpp.

const GlobalStringArray BLOCXX_NAMESPACE::LogAppender::ALL_COMPONENTS = BLOCXX_GLOBAL_STRING_INIT("*") [static]

Pass to createLogAppender to indicate all components.

Definition at line 153 of file LogAppender.hpp.

Definition at line 183 of file LogAppender.hpp.

Definition at line 181 of file LogAppender.hpp.

Referenced by categoryIsEnabled().

Definition at line 182 of file LogAppender.hpp.

Definition at line 180 of file LogAppender.hpp.

Referenced by categoryIsEnabled().

Definition at line 185 of file LogAppender.hpp.

Definition at line 187 of file LogAppender.hpp.

const GlobalString BLOCXX_NAMESPACE::LogAppender::STR_TTCC_MESSAGE_FORMAT = BLOCXX_GLOBAL_STRING_INIT("%r [%t] %-5p %c - %m") [static]

The Log4j TTCC message format - TTCC is acronym for Time Thread Category Component.

"%r [%t] %-5p %c - %m"

Definition at line 158 of file LogAppender.hpp.

const GlobalString BLOCXX_NAMESPACE::LogAppender::TYPE_FILE = BLOCXX_GLOBAL_STRING_INIT("file") [static]

String of the type of the file log appender.

Definition at line 164 of file LogAppender.hpp.

Referenced by createLogAppender().

const GlobalString BLOCXX_NAMESPACE::LogAppender::TYPE_MPFILE = BLOCXX_GLOBAL_STRING_INIT("mpfile") [static]

String of the type of the multi-process file log appender.

Definition at line 166 of file LogAppender.hpp.

Referenced by createLogAppender().

const GlobalString BLOCXX_NAMESPACE::LogAppender::TYPE_NULL = BLOCXX_GLOBAL_STRING_INIT("null") [static]

String of the type of the null log appender.

Definition at line 168 of file LogAppender.hpp.

Referenced by createLogAppender().

const GlobalString BLOCXX_NAMESPACE::LogAppender::TYPE_STDERR = BLOCXX_GLOBAL_STRING_INIT("stderr") [static]

String of the type of the stderr log appender.

Definition at line 162 of file LogAppender.hpp.

Referenced by createLogAppender().

const GlobalString BLOCXX_NAMESPACE::LogAppender::TYPE_SYSLOG = BLOCXX_GLOBAL_STRING_INIT("syslog") [static]

String of the type of the syslog log appender.

Definition at line 160 of file LogAppender.hpp.

Referenced by createLogAppender().


The documentation for this class was generated from the following files: