2012-11-22 03:25:06 +00:00
|
|
|
<?php defined('SYSPATH') OR die('No direct script access.');
|
2011-01-13 14:49:56 +00:00
|
|
|
/**
|
|
|
|
* Syslog log writer.
|
|
|
|
*
|
|
|
|
* @package Kohana
|
|
|
|
* @category Logging
|
|
|
|
* @author Jeremy Bush
|
2012-11-22 03:25:06 +00:00
|
|
|
* @copyright (c) 2012 Kohana Team
|
2011-01-13 14:49:56 +00:00
|
|
|
* @license http://kohanaframework.org/license
|
|
|
|
*/
|
2011-05-16 12:47:16 +00:00
|
|
|
class Kohana_Log_Syslog extends Log_Writer {
|
2011-01-13 14:49:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string The syslog identifier
|
|
|
|
*/
|
|
|
|
protected $_ident;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new syslog logger.
|
|
|
|
*
|
2012-11-22 03:25:06 +00:00
|
|
|
* @link http://www.php.net/manual/function.openlog
|
2011-01-13 14:49:56 +00:00
|
|
|
*
|
2012-11-22 03:25:06 +00:00
|
|
|
* @param string $ident syslog identifier
|
|
|
|
* @param int $facility facility to log to
|
2011-01-13 14:49:56 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct($ident = 'KohanaPHP', $facility = LOG_USER)
|
|
|
|
{
|
|
|
|
$this->_ident = $ident;
|
|
|
|
|
|
|
|
// Open the connection to syslog
|
|
|
|
openlog($this->_ident, LOG_CONS, $facility);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Writes each of the messages into the syslog.
|
|
|
|
*
|
2012-11-22 03:25:06 +00:00
|
|
|
* @param array $messages
|
2011-01-13 14:49:56 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function write(array $messages)
|
|
|
|
{
|
|
|
|
foreach ($messages as $message)
|
|
|
|
{
|
2011-05-16 12:47:16 +00:00
|
|
|
syslog($message['level'], $message['body']);
|
2012-11-22 03:25:06 +00:00
|
|
|
|
|
|
|
if (isset($message['additional']['exception']))
|
|
|
|
{
|
|
|
|
syslog(Log_Writer::$strace_level, $message['additional']['exception']->getTraceAsString());
|
|
|
|
}
|
2011-01-13 14:49:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Closes the syslog connection
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __destruct()
|
|
|
|
{
|
|
|
|
// Close connection to syslog
|
|
|
|
closelog();
|
|
|
|
}
|
|
|
|
|
2011-05-16 12:47:16 +00:00
|
|
|
} // End Kohana_Log_Syslog
|