log4cplus::Logger Class Reference

This is the central class in the log4cplus package. More...

`#include <logger.h>`

Inheritance diagram for log4cplus::Logger:
[legend]
Collaboration diagram for log4cplus::Logger:
[legend]

## Public Member Functions

void | assertion (bool assertionVal, const log4cplus::tstring &msg) const
| If `assertionVal` parameter is `false`, then logs `msg` with FATAL_LOG_LEVEL log level.
void | closeNestedAppenders () const
| Close all attached appenders implementing the AppenderAttachable interface.
bool | isEnabledFor (LogLevel ll) const
| Check whether this logger is enabled for a given LogLevel passed as parameter.
void | log (LogLevel ll, const log4cplus::tstring &message, const char *file=LOG4CPLUS_CALLER_FILE(), int line=LOG4CPLUS_CALLER_LINE(), const char *function=LOG4CPLUS_CALLER_FUNCTION()) const
| This generic form is intended to be used by wrappers.
void | log (spi::InternalLoggingEvent const &) const
void | forcedLog (LogLevel ll, const log4cplus::tstring &message, const char *file=LOG4CPLUS_CALLER_FILE(), int line=LOG4CPLUS_CALLER_LINE(), const char *function=LOG4CPLUS_CALLER_FUNCTION()) const
| This method creates a new logging event and logs the event without further checks.
void | forcedLog (spi::InternalLoggingEvent const &) const
void | callAppenders (const spi::InternalLoggingEvent &event) const
| Call the appenders in the hierrachy starting at `this`.
LogLevel | getChainedLogLevel () const
| Starting from this logger, search the logger hierarchy for a "set" LogLevel and return it.
LogLevel | getLogLevel () const
| Returns the assigned LogLevel, if any, for this Logger.
void | setLogLevel (LogLevel ll)
| Set the LogLevel of this Logger.
Hierarchy & | getHierarchy () const
| Return the the `Hierarchy` where this `Logger` instance is attached.
log4cplus::tstring const & | getName () const
| Return the logger name.
bool | getAdditivity () const
| Get the additivity flag for this Logger instance.
void | setAdditivity (bool additive)
| Set the additivity flag for this Logger instance.
virtual void | addAppender (SharedAppenderPtr newAppender)
| Add an appender.
virtual SharedAppenderPtrList | getAllAppenders ()
| Get all previously added appenders as an Enumeration.
virtual SharedAppenderPtr | getAppender (const log4cplus::tstring &name)
| Get an appender by name.
virtual void | removeAllAppenders ()
| Remove all previously added appenders.
virtual void | removeAppender (SharedAppenderPtr appender)
| Remove the appender passed as parameter from the list of appenders.
virtual void | removeAppender (const log4cplus::tstring &name)
| Remove the appender with the name passed as parameter from the list of appenders.
| Logger () LOG4CPLUS_NOEXCEPT
| Logger (const Logger &rhs) LOG4CPLUS_NOEXCEPT
Logger & | operator= (const Logger &rhs) LOG4CPLUS_NOEXCEPT
| Logger (Logger &&rhs) LOG4CPLUS_NOEXCEPT
Logger & | operator= (Logger &&rhs) LOG4CPLUS_NOEXCEPT
virtual | ~Logger ()
void | swap (Logger &) LOG4CPLUS_NOEXCEPT
Logger | getParent () const
| Used to retrieve the parent of this Logger in the Logger tree.
Public Member Functions inherited from log4cplus::spi::AppenderAttachable
virtual | ~AppenderAttachable ()=0

## Static Public Member Functions

static bool | exists (const log4cplus::tstring &name)
| Returns `true` if the named logger exists (in the default hierarchy).
static LoggerList | getCurrentLoggers ()
static Hierarchy & | getDefaultHierarchy ()
| Return the default Hierarchy instance.
static Logger | getInstance (const log4cplus::tstring &name)
| Retrieve a logger with name `name`.
static Logger | getInstance (const log4cplus::tstring &name, spi::LoggerFactory &factory)
| Like getInstance() except that the type of logger instantiated depends on the type returned by the `spi::LoggerFactory#makeNewLoggerInstance` method of the `factory` parameter.
static Logger | getRoot ()
| Return the root of the default logger hierrachy.
static void | shutdown ()
| Calling this method will safely close and remove all appenders in all the loggers including root contained in the default hierachy.

## Protected Attributes

spi::LoggerImpl * | value = nullptr
| This is a pointer to the implementation class.

## Friends

class | log4cplus::spi::LoggerImpl
class | log4cplus::Hierarchy
class | log4cplus::HierarchyLocker
class | log4cplus::DefaultLoggerFactory

## Detailed Description

This is the central class in the log4cplus package.

One of the distintive features of log4cplus are hierarchical loggers and their evaluation.

Definition at line 69 of file logger.h.

## Constructor & Destructor Documentation

## Logger() [1/3]

log4cplus::Logger::Logger | ( |  | ) |

References LOG4CPLUS_NOEXCEPT.

Referenced by getInstance(), getInstance(), getParent(), getRoot(), Logger(), Logger(), operator=(), operator=(), swap(), and ~Logger().

## Logger() [2/3]

log4cplus::Logger::Logger | ( | const Logger & | rhs | ) |

References LOG4CPLUS_NOEXCEPT, and Logger().

## Logger() [3/3]

log4cplus::Logger::Logger | ( | Logger && | rhs | ) |

References LOG4CPLUS_NOEXCEPT, and Logger().

## ~Logger()

virtual log4cplus::Logger::~Logger | ( |  | ) |

virtual

References Logger().

## Member Function Documentation

## addAppender()

virtual void log4cplus::Logger::addAppender | ( | SharedAppenderPtr | newAppender | ) |

virtual

Add an appender.

Implements log4cplus::spi::AppenderAttachable.

## assertion()

void log4cplus::Logger::assertion | ( | bool | assertionVal,
|  | const log4cplus::tstring & | msg ) const

If `assertionVal` parameter is `false`, then logs `msg` with FATAL_LOG_LEVEL log level.

Parameters

  assertionVal | Truth value of assertion condition.
  msg | The message to print if `assertion` is false.

## callAppenders()

void log4cplus::Logger::callAppenders | ( | const spi::InternalLoggingEvent & | event | ) | const

Call the appenders in the hierrachy starting at `this`.

If no appenders could be found, emit a warning.

This method calls all the appenders inherited from the hierarchy circumventing any evaluation of whether to log or not to log the particular log request.

Parameters

  event | the event to log.

## closeNestedAppenders()

void log4cplus::Logger::closeNestedAppenders | ( |  | ) | const

Close all attached appenders implementing the AppenderAttachable interface.

## exists()

bool log4cplus::Logger::exists | ( | const log4cplus::tstring & | name | ) |

static

Returns `true` if the named logger exists (in the default hierarchy).

Parameters

  name | The name of the logger to search for.

## forcedLog() [1/2]

void log4cplus::Logger::forcedLog | ( | LogLevel | ll,
|  | const log4cplus::tstring & | message,
|  | const char * | file = LOG4CPLUS_CALLER_FILE(),
|  | int | line = LOG4CPLUS_CALLER_LINE(),
|  | const char * | function = LOG4CPLUS_CALLER_FUNCTION() ) const

This method creates a new logging event and logs the event without further checks.

References LOG4CPLUS_CALLER_FILE, LOG4CPLUS_CALLER_FUNCTION, and LOG4CPLUS_CALLER_LINE.

## forcedLog() [2/2]

void log4cplus::Logger::forcedLog | ( | spi::InternalLoggingEvent const & |  | ) | const

## getAdditivity()

bool log4cplus::Logger::getAdditivity | ( |  | ) | const

Get the additivity flag for this Logger instance.

## getAllAppenders()

virtual SharedAppenderPtrList log4cplus::Logger::getAllAppenders | ( |  | ) |

virtual

Get all previously added appenders as an Enumeration.

Implements log4cplus::spi::AppenderAttachable.

## getAppender()

virtual SharedAppenderPtr log4cplus::Logger::getAppender | ( | const log4cplus::tstring & | name | ) |

virtual

Get an appender by name.

Implements log4cplus::spi::AppenderAttachable.

## getChainedLogLevel()

LogLevel log4cplus::Logger::getChainedLogLevel | ( |  | ) | const

Starting from this logger, search the logger hierarchy for a "set" LogLevel and return it.

Otherwise, return the LogLevel of the root logger.

The Logger class is designed so that this method executes as quickly as possible.

## getCurrentLoggers()

LoggerList log4cplus::Logger::getCurrentLoggers | ( |  | ) |

static

## getDefaultHierarchy()

Hierarchy & log4cplus::Logger::getDefaultHierarchy | ( |  | ) |

static

Return the default Hierarchy instance.

References log4cplus::Hierarchy.

Referenced by log4cplus::BasicConfigurator::BasicConfigurator(), log4cplus::BasicConfigurator::doConfigure(), log4cplus::PropertyConfigurator::doConfigure(), log4cplus::PropertyConfigurator::PropertyConfigurator(), log4cplus::PropertyConfigurator::PropertyConfigurator(), and log4cplus::PropertyConfigurator::PropertyConfigurator().

## getHierarchy()

Hierarchy & log4cplus::Logger::getHierarchy | ( |  | ) | const

Return the the `Hierarchy` where this `Logger` instance is attached.

References log4cplus::Hierarchy.

## getInstance() [1/2]

Logger log4cplus::Logger::getInstance | ( | const log4cplus::tstring & | name | ) |

static

Retrieve a logger with name `name`.

If the named logger already exists, then the existing instance will be returned. Otherwise, a new instance is created.

By default, loggers do not have a set LogLevel but inherit it from the hierarchy. This is one of the central features of log4cplus.

Parameters

  name | The name of the logger to retrieve.

References Logger().

Referenced by log4cplus::detail::macros_get_logger(), and log4cplus::detail::macros_get_logger().

## getInstance() [2/2]

Logger log4cplus::Logger::getInstance | ( | const log4cplus::tstring & | name,
|  | spi::LoggerFactory & | factory )

static

Like getInstance() except that the type of logger instantiated depends on the type returned by the `spi::LoggerFactory#makeNewLoggerInstance` method of the `factory` parameter.

This method is intended to be used by sub-classes.

Parameters

  name | The name of the logger to retrieve.
  factory | A `spi::LoggerFactory` implementation that will actually create a new Instance.

References Logger().

## getLogLevel()

LogLevel log4cplus::Logger::getLogLevel | ( |  | ) | const

Returns the assigned LogLevel, if any, for this Logger.

Returns
  LogLevel - the assigned LogLevel, can be `NOT_SET_LOG_LEVEL`.

## getName()

log4cplus::tstring const & log4cplus::Logger::getName | ( |  | ) | const

Return the logger name.

## getParent()

Logger log4cplus::Logger::getParent | ( |  | ) | const

Used to retrieve the parent of this Logger in the Logger tree.

References getParent(), and Logger().

Referenced by getParent().

## getRoot()

Logger log4cplus::Logger::getRoot | ( |  | ) |

static

Return the root of the default logger hierrachy.

The root logger is always instantiated and available. It's name is "root".

Nevertheless, calling `Logger.getInstance("root")` does not retrieve the root logger but a logger just under root named "root".

References Logger().

## isEnabledFor()

bool log4cplus::Logger::isEnabledFor | ( | LogLevel | ll | ) | const

Check whether this logger is enabled for a given LogLevel passed as parameter.

Returns
  boolean True if this logger is enabled for `ll`.

## log() [1/2]

void log4cplus::Logger::log | ( | LogLevel | ll,
|  | const log4cplus::tstring & | message,
|  | const char * | file = LOG4CPLUS_CALLER_FILE(),
|  | int | line = LOG4CPLUS_CALLER_LINE(),
|  | const char * | function = LOG4CPLUS_CALLER_FUNCTION() ) const

This generic form is intended to be used by wrappers.

References LOG4CPLUS_CALLER_FILE, LOG4CPLUS_CALLER_FUNCTION, and LOG4CPLUS_CALLER_LINE.

## log() [2/2]

void log4cplus::Logger::log | ( | spi::InternalLoggingEvent const & |  | ) | const

## operator=() [1/2]

Logger & log4cplus::Logger::operator= | ( | const Logger & | rhs | ) |

References LOG4CPLUS_NOEXCEPT, and Logger().

## operator=() [2/2]

Logger & log4cplus::Logger::operator= | ( | Logger && | rhs | ) |

References LOG4CPLUS_NOEXCEPT, and Logger().

## removeAllAppenders()

virtual void log4cplus::Logger::removeAllAppenders | ( |  | ) |

virtual

Remove all previously added appenders.

Implements log4cplus::spi::AppenderAttachable.

## removeAppender() [1/2]

virtual void log4cplus::Logger::removeAppender | ( | const log4cplus::tstring & | name | ) |

virtual

Remove the appender with the name passed as parameter from the list of appenders.

Implements log4cplus::spi::AppenderAttachable.

## removeAppender() [2/2]

virtual void log4cplus::Logger::removeAppender | ( | SharedAppenderPtr | appender | ) |

virtual

Remove the appender passed as parameter from the list of appenders.

Implements log4cplus::spi::AppenderAttachable.

## setAdditivity()

void log4cplus::Logger::setAdditivity | ( | bool | additive | ) |

Set the additivity flag for this Logger instance.

## setLogLevel()

void log4cplus::Logger::setLogLevel | ( | LogLevel | ll | ) |

Set the LogLevel of this Logger.

## shutdown()

void log4cplus::Logger::shutdown | ( |  | ) |

static

Calling this method will safely close and remove all appenders in all the loggers including root contained in the default hierachy.

Some appenders such as SocketAppender need to be closed before the application exits. Otherwise, pending logging events might be lost.

The `shutdown` method is careful to close nested appenders before closing regular appenders. This is allows configurations where a regular appender is attached to a logger and again to a nested appender.

## swap()

void log4cplus::Logger::swap | ( | Logger & |  | ) |

References LOG4CPLUS_NOEXCEPT, Logger(), and swap().

Referenced by swap().

## Friends And Related Symbol Documentation

## log4cplus::DefaultLoggerFactory

friend class log4cplus::DefaultLoggerFactory

friend

Definition at line 304 of file logger.h.

References log4cplus::DefaultLoggerFactory.

Referenced by log4cplus::DefaultLoggerFactory.

## log4cplus::Hierarchy

friend class log4cplus::Hierarchy

friend

Definition at line 302 of file logger.h.

References log4cplus::Hierarchy.

Referenced by getDefaultHierarchy(), getHierarchy(), and log4cplus::Hierarchy.

## log4cplus::HierarchyLocker

friend class log4cplus::HierarchyLocker

friend

Definition at line 303 of file logger.h.

References log4cplus::HierarchyLocker.

Referenced by log4cplus::HierarchyLocker.

## log4cplus::spi::LoggerImpl

friend class log4cplus::spi::LoggerImpl

friend

Definition at line 301 of file logger.h.

References log4cplus::spi::LoggerImpl.

Referenced by log4cplus::spi::LoggerImpl.

## Member Data Documentation

## value

spi::LoggerImpl* log4cplus::Logger::value = nullptr

protected

This is a pointer to the implementation class.

Definition at line 285 of file logger.h.

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

- logger.h