PHP Class lithium\analysis\Logger

When configuring adapters, you may specify one or more priorities for each, using the 'priority' key. This key can be a single priority level (string), or an array of multiple levels. When a log message is written, all adpaters that are configured to accept the priority level with which the message was written will receive the message. {{{ Logger::config(array( 'default' => array('adapter' => 'Syslog'), 'badnews' => array( 'adapter' => 'File', 'priority' => array('emergency', 'alert', 'critical', 'error') ) )); }}} In the above configuration, all messages will be written to the system log (syslogd), but only messages with the priority error or higher will be logged to a file. Messages can then be written to the log(s) using the write() method: {{{ Logger::write('alert', 'This is an alert-level message that will be logged in 2 places'); }}} Messages can also be written using the log priorty as a method name: {{{ Logger::alert('This is an alert-level message that will be logged in 2 places'); }}} This works identically to the above. The message priority levels which Logger supports are as follows: emergency, alert, critical, error, warning, notice, info and debug. Attempting to use any other priority level will raise an exception. See the list of available adapters for more information on what adapters are available, and how to configure them.
See also: lithium\analysis\logger\adapter
Inheritance: extends lithium\core\Adaptable
显示文件 Open project: unionofrad/lithium Class Usage Examples

Protected Properties

Property Type Description
$_adapters Libraries::locate() compatible path to adapters for this class.
$_configurations Stores configurations for cache adapters.
$_priorities array An array of valid message priorities.

Public Methods

Method Description
__callStatic ( string $priority, array $params ) : boolean Acts as a proxy for the write() method, allowing log message priority names to be called as methods, i.e.: Logger::emergency('Something bad happened.'); This is equivalent to Logger::write('emergency', 'Something bad happened')
respondsTo ( string $method, boolean $internal = false ) : boolean Determines if a given method can be called.
write ( string $priority, string $message, array $options = [] ) : boolean Writes a message to one or more log adapters, where the adapters that are written to are the ones that respond to the given priority level.

Protected Methods

Method Description
_configsByPriority ( string $priority, string $message, array $options = [] ) : array Gets the names of the adapter configurations that respond to a specific priority. The list of adapter configurations returned will be used to write a message with the given priority.
_initConfig ( string $name, array $config ) : array This method is called automatically to initialize the default configuration of a log adapter, such that the adapter defaults to accepting log messages of any priority (i.e. the 'priority' key is set to true).

Method Details

__callStatic() public static method

Acts as a proxy for the write() method, allowing log message priority names to be called as methods, i.e.: Logger::emergency('Something bad happened.'); This is equivalent to Logger::write('emergency', 'Something bad happened')
public static __callStatic ( string $priority, array $params ) : boolean
$priority string The name of the method called on the `Logger` class. This should map to a log type.
$params array An array of parameters passed in the method.
return boolean Returns `true` or `false`, depending on the success of the `write()` method.

_configsByPriority() protected static method

Gets the names of the adapter configurations that respond to a specific priority. The list of adapter configurations returned will be used to write a message with the given priority.
protected static _configsByPriority ( string $priority, string $message, array $options = [] ) : array
$priority string The priority level of a message to be written.
$message string The message to write to the adapter.
$options array Adapter-specific options.
return array Returns an array of names of configurations which are set up to respond to the message priority specified in `$priority`, or configured to respond to _all_ message priorities.

_initConfig() protected static method

This method is called automatically to initialize the default configuration of a log adapter, such that the adapter defaults to accepting log messages of any priority (i.e. the 'priority' key is set to true).
protected static _initConfig ( string $name, array $config ) : array
$name string The name of the logger configuration.
$config array The logger configuration as specified in application code.
return array Returns an array of configuration data, merged with default values.

respondsTo() public static method

Determines if a given method can be called.
public static respondsTo ( string $method, boolean $internal = false ) : boolean
$method string Name of the method.
$internal boolean Provide `true` to perform check from inside the class/object. When `false` checks also for public visibility; defaults to `false`.
return boolean Returns `true` if the method can be called, `false` otherwise.

write() public static method

Writes a message to one or more log adapters, where the adapters that are written to are the ones that respond to the given priority level.
public static write ( string $priority, string $message, array $options = [] ) : boolean
$priority string The priority of the log message to be written.
$message string The message to be written.
$options array An array of adapter-specific options that may be passed when writing log messages. Some options are also handled by `Logger` itself: - `'name'` _string_: This option can be specified if you wish to write to a specific adapter configuration, instead of writing to the adapter(s) that respond to the given priority.
return boolean Returns `true` if all log writes succeeded, or `false` if _any or all_ writes failed.

Property Details

$_adapters protected_oe static_oe property

Libraries::locate() compatible path to adapters for this class.
See also: lithium\core\Libraries::locate()
protected static $_adapters

$_configurations protected_oe static_oe property

Stores configurations for cache adapters.
protected static $_configurations

$_priorities protected_oe static_oe property

An array of valid message priorities.
protected static array $_priorities
return array