Kohana_Log
Message logging with observer-based log writing.
Properties
string timestampstring(11) "Y-m-d H:i:s"Methods
public static instance ( )
Get the singleton instance of this class and enable writing at shutdown.
Returns:
Kohana_Log
Source:
public static function instance()
{
if (self::$_instance === NULL)
{
// Create a new instance
self::$_instance = new self;
// Write the logs at shutdown
register_shutdown_function(array(self::$_instance, 'write'));
}
return self::$_instance;
}
public attach ( object $writer, array $types = NULL )
Attaches a log writer.
Returns:
$this
Source:
public function attach(Kohana_Log_Writer $writer, array $types = NULL)
{
$this->_writers["{$writer}"] = array
(
'object' => $writer,
'types' => $types
);
return $this;
}
public detach ( object $writer )
Detaches a log writer.
Returns:
$this
Source:
public function detach(Kohana_Log_Writer $writer)
{
// Remove the writer
unset($this->_writers["{$writer}"]);
return $this;
}
public add ( string $type, string $message )
Adds a message to the log.
Returns:
$this
Source:
public function add($type, $message)
{
// Create a new message and timestamp it
$this->_messages[] = array
(
'time' => date(self::$timestamp),
'type' => $type,
'body' => $message,
);
return $this;
}
public write ( )
Write and clear all of the messages.
Returns:
void
Source:
public function write()
{
if (empty($this->_messages))
{
// There is nothing to write, move along
return;
}
// Import all messages locally
$messages = $this->_messages;
// Reset the messages array
$this->_messages = array();
foreach ($this->_writers as $writer)
{
if (empty($writer['types']))
{
// Write all of the messages
$writer['object']->write($messages);
}
else
{
// Filtered messages
$filtered = array();
foreach ($messages as $message)
{
if (in_array($message['type'], $writer['types']))
{
// Writer accepts this kind of message
$filtered[] = $message;
}
}
// Write the filtered messages
$writer['object']->write($filtered);
}
}
}
final private __construct ( )
Source:
final private function __construct()
{
// Enforce singleton behavior
}
private __clone ( )
Source:
private function __clone()
{
// Enforce singleton behavior
}