Class cLog
This class contains the main functionalities for the logging in
CONTENIDO.
Examples:
$writer = cLogWriter::factory("File", array('destination' =>
'contenido.log')); $log = new cLog($writer);
$log->addPriority("CONTENIDO", 10); $log->log("Contenido Log Message.",
"CONTENIDO"); $log->contenido("Same log entry in short notation.");
$log->removePriority("CONTENIDO");
$log->emerg("System down.");
$log->log('Notice Log Message', cLog::NOTICE);
$log->buffer('Buffered Log Message', cLog::WARN); $log->commit();
Methods summary
public
|
#
__construct( mixed $writer = false )
Creates a new instance of the CONTENIDO Log mechanism.
Creates a new instance of the CONTENIDO Log mechanism.
The log format interface of cLog is capable of being extended by subclasses.
See the note about the log shortcuts below.
About Log Shortcuts
Log shortcuts are placeholders which are replaced when a log entry is
created. Placeholders start with a percentage sign (%) and contain one or more
characters. Each placeholder is handled by an own function which decides what to
do.
Parameters
- $writer
mixed $writer Writer object (any subclass of cLogWriter), or false if cLog should
handle the writer creation
|
public
cLogWriter
|
#
getWriter( )
Returns the local writer instance.
Returns the local writer instance.
Returns
|
public
|
#
setWriter( cLogWriter $writer )
Sets the local writer instance.
Sets the local writer instance.
Parameters
|
public
boolean
|
#
setShortcutHandler( string $shortcut, string $handler )
Defines a custom shortcut handler.
Defines a custom shortcut handler.
Each shortcut handler receives an array with the message and the priority of
the entry.
Parameters
- $shortcut
string $shortcut Shortcut name
- $handler
string $handler Name of the function to call
Returns
boolean True if setting was successful
Throws
|
public
boolean
|
#
unsetShortcutHandler( string $shortcut )
Unsets a specific shortcut handler.
Unsets a specific shortcut handler.
Parameters
- $shortcut
string $shortcut Name of the shortcut
Returns
boolean
Throws
|
public
|
#
buffer( string $message, mixed $priority = NULL )
Buffers a log message for committing them on a later moment.
Buffers a log message for committing them on a later moment.
Parameters
- $message
string $message Message to buffer
- $priority
mixed $priority Priority of the log entry (optional)
|
public
|
#
commit( boolean $revoke = true )
Commits all buffered messages and empties the message buffer if parameter is
not false.
Commits all buffered messages and empties the message buffer if parameter is
not false.
Parameters
- $revoke
boolean $revoke Flag, whether the buffer is cleared or not (optional, default: true)
|
public
|
#
revoke( )
Empties the message buffer.
Empties the message buffer.
|
public
|
#
log( string $message, mixed $priority = NULL )
Logs a message using the local writer instance
Logs a message using the local writer instance
Parameters
- $message
string $message Message to log
- $priority
mixed $priority Priority of the log entry (optional)
|
public
|
#
addPriority( string $name, integer $value )
Adds a new priority to the log.
Adds a new priority to the log.
Parameters
- $name
string $name Name of the log priority
- $value
integer $value Index value of the log priority
Throws
|
public
|
#
removePriority( string $name )
Removes a priority from log. Default properties can not be removed.
Removes a priority from log. Default properties can not be removed.
Parameters
- $name
string $name Name of the log priority to remove
Throws
|
public
|
#
__call( string $method, array $arguments )
Magic call method for direct priority named calls.
Magic call method for direct priority named calls.
Parameters
- $method
string $method Name of the method
- $arguments
array $arguments Array with the method arguments
Throws
|
public
string
|
#
shDate( )
Shortcut Handler Date. Returns the current date
Shortcut Handler Date. Returns the current date
Returns
string The current date
|
public
string
|
#
shLevel( mixed $info )
Shortcut Handler Level. Returns the canonical name of the priority. The
canonical name is padded to 10 characters to achieve a better formatting.
Shortcut Handler Level. Returns the canonical name of the priority. The
canonical name is padded to 10 characters to achieve a better formatting.
Returns
string The canonical log level
|
public
string
|
#
shMessage( mixed $info )
Shortcut Handler Message. Returns the log message.
Shortcut Handler Message. Returns the log message.
Returns
string The log message
|
Properties summary
protected
cLogWriter
|
$_writer
|
|
#
Contains the local log writer instance.
Contains the local log writer instance.
|
protected
array
|
$_shortcutHandlers
|
array() |
#
Contains all shortcut handlers
Contains all shortcut handlers
|
protected
array
|
$_priorities
|
array() |
#
Contains all available priorities
Contains all available priorities
|
protected
array
|
$_defaultPriorities
|
array() |
#
Contains all default priorities
Contains all default priorities
|
protected
array
|
$_buffer
|
array() |
#
Contains all buffered messages
Contains all buffered messages
|