blocxx
BLOCXX_NAMESPACE::LogAppender Class Referenceabstract

#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

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 = { "*", 0, {0, PTHREAD_MUTEX_INITIALIZER} }
 Pass to createLogAppender to indicate all components.
 
static const GlobalStringArray ALL_CATEGORIES = { "*", 0, {0, PTHREAD_MUTEX_INITIALIZER} }
 Pass to createLogAppender to indicate all categories.
 
static const GlobalString STR_TTCC_MESSAGE_FORMAT = { "%r [%t] %-5p %c - %m", 0, {0, PTHREAD_MUTEX_INITIALIZER} }
 The Log4j TTCC message format - TTCC is acronym for Time Thread Category Component.
 
static const GlobalString TYPE_SYSLOG = { "syslog", 0, {0, PTHREAD_MUTEX_INITIALIZER} }
 String of the type of the syslog log appender.
 
static const GlobalString TYPE_STDERR = { "stderr", 0, {0, PTHREAD_MUTEX_INITIALIZER} }
 String of the type of the stderr log appender.
 
static const GlobalString TYPE_FILE = { "file", 0, {0, PTHREAD_MUTEX_INITIALIZER} }
 String of the type of the file log appender.
 
static const GlobalString TYPE_MPFILE = { "mpfile", 0, {0, PTHREAD_MUTEX_INITIALIZER} }
 String of the type of the multi-process file log appender.
 
static const GlobalString TYPE_NULL = { "null", 0, {0, PTHREAD_MUTEX_INITIALIZER} }
 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)
 
- Protected Member Functions inherited from BLOCXX_NAMESPACE::IntrusiveCountableBase
 IntrusiveCountableBase ()
 
 IntrusiveCountableBase (const IntrusiveCountableBase &)
 
IntrusiveCountableBaseoperator= (const IntrusiveCountableBase &)
 
virtual ~IntrusiveCountableBase ()
 

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

◆ ~LogAppender()

BLOCXX_NAMESPACE::LogAppender::~LogAppender ( )
virtual

Definition at line 79 of file LogAppender.cpp.

◆ LogAppender()

Member Function Documentation

◆ categoryIsEnabled()

bool BLOCXX_NAMESPACE::LogAppender::categoryIsEnabled ( const String & category) const

Definition at line 271 of file LogAppender.cpp.

References m_allCategories, and m_categories.

Referenced by componentAndCategoryAreEnabled().

◆ componentAndCategoryAreEnabled()

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

Definition at line 278 of file LogAppender.cpp.

References categoryIsEnabled(), m_allComponents, and m_components.

Referenced by logMessage().

◆ createLogAppender()

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 304 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::Format::c_str(), 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.

◆ doProcessLogMessage()

virtual void BLOCXX_NAMESPACE::LogAppender::doProcessLogMessage ( const String & formattedMessage,
const LogMessage & message ) const
privatepure virtual

◆ getCurrentLogAppender()

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 133 of file LogAppender.cpp.

References getDefaultLogAppender(), and getThreadLogAppender().

◆ getDefaultLogAppender()

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 149 of file LogAppender.cpp.

References BLOCXX_NAMESPACE::callOnce().

Referenced by getCurrentLogAppender().

◆ getLogLevel()

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

Definition at line 111 of file LogAppender.hpp.

References m_logLevel.

◆ getThreadLogAppender()

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 181 of file LogAppender.cpp.

References BLOCXX_NAMESPACE::callOnce().

Referenced by getCurrentLogAppender().

◆ logMessage()

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 259 of file LogAppender.cpp.

References BLOCXX_NAMESPACE::LogMessage::category, BLOCXX_NAMESPACE::LogMessage::component, componentAndCategoryAreEnabled(), doProcessLogMessage(), m_formatter, and BLOCXX_NAMESPACE::StringBuffer::releaseString().

◆ setDefaultLogAppender()

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 164 of file LogAppender.cpp.

References BLOCXX_NAMESPACE::callOnce(), and BLOCXX_NAMESPACE::IntrusiveReference< T >::swap().

◆ setThreadLogAppender()

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 212 of file LogAppender.cpp.

References BLOCXX_ASSERTMSG, BLOCXX_NAMESPACE::callOnce(), and BLOCXX_NAMESPACE::freeThreadLogAppender().

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

Member Data Documentation

◆ ALL_CATEGORIES

const GlobalStringArray BLOCXX_NAMESPACE::LogAppender::ALL_CATEGORIES = { "*", 0, {0, PTHREAD_MUTEX_INITIALIZER} }
static

Pass to createLogAppender to indicate all categories.

Definition at line 155 of file LogAppender.hpp.

Referenced by BLOCXX_NAMESPACE::CerrAppender::CerrAppender(), BLOCXX_NAMESPACE::MultiAppender::MultiAppender(), and BLOCXX_NAMESPACE::MultiAppender::MultiAppender().

◆ ALL_COMPONENTS

const GlobalStringArray BLOCXX_NAMESPACE::LogAppender::ALL_COMPONENTS = { "*", 0, {0, PTHREAD_MUTEX_INITIALIZER} }
static

Pass to createLogAppender to indicate all components.

Definition at line 153 of file LogAppender.hpp.

Referenced by BLOCXX_NAMESPACE::CerrAppender::CerrAppender(), BLOCXX_NAMESPACE::MultiAppender::MultiAppender(), and BLOCXX_NAMESPACE::MultiAppender::MultiAppender().

◆ m_allCategories

bool BLOCXX_NAMESPACE::LogAppender::m_allCategories
private

Definition at line 183 of file LogAppender.hpp.

Referenced by categoryIsEnabled(), and LogAppender().

◆ m_allComponents

bool BLOCXX_NAMESPACE::LogAppender::m_allComponents
private

Definition at line 181 of file LogAppender.hpp.

Referenced by componentAndCategoryAreEnabled(), and LogAppender().

◆ m_categories

SortedVectorSet<String> BLOCXX_NAMESPACE::LogAppender::m_categories
private

Definition at line 182 of file LogAppender.hpp.

Referenced by categoryIsEnabled(), and LogAppender().

◆ m_components

SortedVectorSet<String> BLOCXX_NAMESPACE::LogAppender::m_components
private

Definition at line 180 of file LogAppender.hpp.

Referenced by componentAndCategoryAreEnabled(), and LogAppender().

◆ m_formatter

LogMessagePatternFormatter BLOCXX_NAMESPACE::LogAppender::m_formatter
private

Definition at line 185 of file LogAppender.hpp.

Referenced by LogAppender(), and logMessage().

◆ m_logLevel

ELogLevel BLOCXX_NAMESPACE::LogAppender::m_logLevel
private

Definition at line 187 of file LogAppender.hpp.

Referenced by getLogLevel(), and LogAppender().

◆ STR_TTCC_MESSAGE_FORMAT

const GlobalString BLOCXX_NAMESPACE::LogAppender::STR_TTCC_MESSAGE_FORMAT = { "%r [%t] %-5p %c - %m", 0, {0, PTHREAD_MUTEX_INITIALIZER} }
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.

◆ TYPE_FILE

const GlobalString BLOCXX_NAMESPACE::LogAppender::TYPE_FILE = { "file", 0, {0, PTHREAD_MUTEX_INITIALIZER} }
static

String of the type of the file log appender.

Definition at line 164 of file LogAppender.hpp.

Referenced by createLogAppender().

◆ TYPE_MPFILE

const GlobalString BLOCXX_NAMESPACE::LogAppender::TYPE_MPFILE = { "mpfile", 0, {0, PTHREAD_MUTEX_INITIALIZER} }
static

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

Definition at line 166 of file LogAppender.hpp.

Referenced by createLogAppender().

◆ TYPE_NULL

const GlobalString BLOCXX_NAMESPACE::LogAppender::TYPE_NULL = { "null", 0, {0, PTHREAD_MUTEX_INITIALIZER} }
static

String of the type of the null log appender.

Definition at line 168 of file LogAppender.hpp.

Referenced by createLogAppender().

◆ TYPE_STDERR

const GlobalString BLOCXX_NAMESPACE::LogAppender::TYPE_STDERR = { "stderr", 0, {0, PTHREAD_MUTEX_INITIALIZER} }
static

String of the type of the stderr log appender.

Definition at line 162 of file LogAppender.hpp.

Referenced by createLogAppender().

◆ TYPE_SYSLOG

const GlobalString BLOCXX_NAMESPACE::LogAppender::TYPE_SYSLOG = { "syslog", 0, {0, PTHREAD_MUTEX_INITIALIZER} }
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: