# Class Logger

This is the central class in the log4php package. All logging operations are done through this class.

The main logging methods are:

- `Logger::trace()`
- `Logger::debug()`
- `Logger::info()`
- `Logger::warn()`
- `Logger::error()`
- `Logger::fatal()`

#### Direct known subclasses

LoggerRoot
Package: log4php
License: Apache License, Version 2.0
Version: SVN: $Id: Logger.php 1395241 2012-10-07 08:28:53Z ihabunek $
Link: http://logging.apache.org/log4php
Located at Logger.php

Methods summary
`public` | # `__construct( string $name )` Constructor. Constructor. #### Parameters $name `string` $name Name of the logger.
`public string` | # `getName( )` Returns the logger name. Returns the logger name. #### Returns `string`
`public `Logger`` | # `getParent( )` Returns the parent Logger. Can be null if this is the root logger. Returns the parent Logger. Can be null if this is the root logger. #### Returns ``Logger``
`public` | # `trace( mixed $message, Exception $throwable = null )` Log a message object with the TRACE level. Log a message object with the TRACE level. #### Parameters $message `mixed` $message message $throwable `Exception` $throwable Optional throwable information to include in the logging event.
`public` | # `debug( mixed $message, Exception $throwable = null )` Log a message object with the DEBUG level. Log a message object with the DEBUG level. #### Parameters $message `mixed` $message message $throwable `Exception` $throwable Optional throwable information to include in the logging event.
`public` | # `info( mixed $message, Exception $throwable = null )` Log a message object with the INFO Level. Log a message object with the INFO Level. #### Parameters $message `mixed` $message message $throwable `Exception` $throwable Optional throwable information to include in the logging event.
`public` | # `warn( mixed $message, Exception $throwable = null )` Log a message with the WARN level. Log a message with the WARN level. #### Parameters $message `mixed` $message message $throwable `Exception` $throwable Optional throwable information to include in the logging event.
`public` | # `error( mixed $message, Exception $throwable = null )` Log a message object with the ERROR level. Log a message object with the ERROR level. #### Parameters $message `mixed` $message message $throwable `Exception` $throwable Optional throwable information to include in the logging event.
`public` | # `fatal( mixed $message, Exception $throwable = null )` Log a message object with the FATAL level. Log a message object with the FATAL level. #### Parameters $message `mixed` $message message $throwable `Exception` $throwable Optional throwable information to include in the logging event.
`public` | # `log( `LoggerLevel` $level, mixed $message, Exception $throwable = null )` Log a message using the provided logging level. Log a message using the provided logging level. #### Parameters $level ``LoggerLevel`` $level The logging level. $message `mixed` $message Message to log. $throwable `Exception` $throwable Optional throwable information to include in the logging event.
`public` | # `logEvent( `LoggerLoggingEvent` $event )` Logs an already prepared logging event object. Logs an already prepared logging event object. #### Parameters $event ``LoggerLoggingEvent`` $event
`public` | # `assertLog( boolean $assertion = true, string $msg = '' )` If assertion parameter evaluates as false, then logs the message using the ERROR level. If assertion parameter evaluates as false, then logs the message using the ERROR level. #### Parameters $assertion `boolean` $assertion $msg `string` $msg message to log
`public` | # `forcedLog( string $fqcn, Exception $throwable, `LoggerLevel` $level, mixed $message )` This method creates a new logging event and logs the event without further checks. This method creates a new logging event and logs the event without further checks. It should not be called directly. Use `Logger::trace()`, `Logger::debug()`, `Logger::info()`, `Logger::warn()`, `Logger::error()` and `Logger::fatal()` wrappers. #### Parameters $fqcn `string` $fqcn Fully qualified class name of the Logger $throwable `Exception` $throwable Optional throwable information to include in the logging event. $level ``LoggerLevel`` $level log level $message `mixed` $message message to log
`public` | # `callAppenders( `LoggerLoggingEvent` $event )` Forwards the given logging event to all linked appenders. Forwards the given logging event to all linked appenders. #### Parameters $event ``LoggerLoggingEvent`` $event
`public boolean` | # `isEnabledFor( `LoggerLevel` $level )` Check whether this Logger is enabled for a given Level passed as parameter. Check whether this Logger is enabled for a given Level passed as parameter. #### Parameters $level ``LoggerLevel`` level #### Returns `boolean`
`public boolean` | # `isTraceEnabled( )` Check whether this Logger is enabled for the TRACE Level. Check whether this Logger is enabled for the TRACE Level. #### Returns `boolean`
`public boolean` | # `isDebugEnabled( )` Check whether this Logger is enabled for the DEBUG Level. Check whether this Logger is enabled for the DEBUG Level. #### Returns `boolean`
`public boolean` | # `isInfoEnabled( )` Check whether this Logger is enabled for the INFO Level. Check whether this Logger is enabled for the INFO Level. #### Returns `boolean`
`public boolean` | # `isWarnEnabled( )` Check whether this Logger is enabled for the WARN Level. Check whether this Logger is enabled for the WARN Level. #### Returns `boolean`
`public boolean` | # `isErrorEnabled( )` Check whether this Logger is enabled for the ERROR Level. Check whether this Logger is enabled for the ERROR Level. #### Returns `boolean`
`public boolean` | # `isFatalEnabled( )` Check whether this Logger is enabled for the FATAL Level. Check whether this Logger is enabled for the FATAL Level. #### Returns `boolean`
`public` | # `addAppender( `LoggerAppender` $appender )` Adds a new appender to the Logger. Adds a new appender to the Logger. #### Parameters $appender ``LoggerAppender`` $appender The appender to add.
`public` | # `removeAllAppenders( )` Removes all appenders from the Logger. Removes all appenders from the Logger.
`public` | # `removeAppender( mixed $appender )` Remove the appender passed as parameter form the Logger. Remove the appender passed as parameter form the Logger. #### Parameters $appender `mixed` $appender an appender name or a `LoggerAppender` instance.
`public array` | # `getAllAppenders( )` Returns the appenders linked to this logger as an array. Returns the appenders linked to this logger as an array. #### Returns `array` collection of appender names
`public `LoggerAppender`` | # `getAppender( mixed $name )` Returns a linked appender by name. Returns a linked appender by name. #### Returns ``LoggerAppender``
`public` | # `setAdditivity( boolean $additive )` Sets the additivity flag. Sets the additivity flag. #### Parameters $additive `boolean` $additive
`public boolean` | # `getAdditivity( )` Returns the additivity flag. Returns the additivity flag. #### Returns `boolean`
`public `LoggerLevel`` | # `getEffectiveLevel( )` Starting from this Logger, search the Logger hierarchy for a non-null level and return it. Starting from this Logger, search the Logger hierarchy for a non-null level and return it. #### Returns ``LoggerLevel`` or null #### See ``LoggerLevel``
`public `LoggerLevel`` | # `getLevel( )` Get the assigned Logger level. Get the assigned Logger level. #### Returns ``LoggerLevel`` The assigned level or null if none is assigned.
`public` | # `setLevel( `LoggerLevel` $level = null )` Set the Logger level. Set the Logger level. Use LoggerLevel::getLevelXXX() methods to get a LoggerLevel object, e.g. `<span class="php-var">$logger</span>->setLevel(LoggerLevel::getLevelInfo());` #### Parameters $level ``LoggerLevel`` $level The level to set, or NULL to clear the logger level.
`public boolean` | # `isAttached( `LoggerAppender` $appender )` Checks whether an appender is attached to this logger instance. Checks whether an appender is attached to this logger instance. #### Parameters $appender ``LoggerAppender`` $appender #### Returns `boolean`
`public` | # `setParent( `Logger` $logger )` Sets the parent logger. Sets the parent logger. #### Parameters $logger ``Logger`` $logger
`public static `LoggerHierarchy`` | # `getHierarchy( )` Returns the hierarchy used by this Logger. Returns the hierarchy used by this Logger. Caution: do not use this hierarchy unless you have called initialize(). To get Loggers, use the Logger::getLogger and Logger::getRootLogger methods instead of operating on on the hierarchy directly. #### Returns ``LoggerHierarchy``
`public static `Logger`` | # `getLogger( string $name )` Returns a Logger by name. If it does not exist, it will be created. Returns a Logger by name. If it does not exist, it will be created. #### Parameters $name `string` $name The logger name #### Returns ``Logger``
`public static `LoggerRoot`` | # `getRootLogger( )` Returns the Root Logger. Returns the Root Logger. #### Returns ``LoggerRoot``
`public static boolean` | # `clear( )` Clears all Logger definitions from the logger hierarchy. Clears all Logger definitions from the logger hierarchy. #### Returns `boolean`
`public static` | # `resetConfiguration( )` Destroy configurations for logger definitions Destroy configurations for logger definitions
`public static boolean` | # `exists( string $name )` check if a given logger exists. check if a given logger exists. #### Parameters $name `string` $name logger name #### Returns `boolean`
`public static array` | # `getCurrentLoggers( )` Returns an array this whole Logger instances. Returns an array this whole Logger instances. #### Returns `array` #### See ``Logger``
`public static` | # `configure( string|array $configuration = null, string|`LoggerConfigurator` $configurator = null )` Configures log4php. Configures log4php. This method needs to be called before the first logging event has occured. If this method is not called before then the default configuration will be used. #### Parameters $configuration `string|array` $configuration Either a path to the configuration file, or a configuration array. $configurator `string|`LoggerConfigurator`` $configurator A custom configurator class: either a class name (string), or an object which implements the LoggerConfigurator interface. If left empty, the default configurator implementation will be used.