2012-11-09 12:18:50 +00:00
|
|
|
<?php defined('SYSPATH') OR die('No direct script access.');
|
2010-08-21 04:43:03 +00:00
|
|
|
/**
|
|
|
|
* Syslog log writer.
|
|
|
|
*
|
|
|
|
* @package Kohana
|
|
|
|
* @category Logging
|
|
|
|
* @author Jeremy Bush
|
2012-11-09 12:18:50 +00:00
|
|
|
* @copyright (c) 2012 Kohana Team
|
2011-05-13 06:00:25 +00:00
|
|
|
* @license http://kohanaframework.org/license
|
2010-08-21 04:43:03 +00:00
|
|
|
*/
|
2011-05-13 06:00:25 +00:00
|
|
|
class Kohana_Log_Syslog extends Log_Writer {
|
2010-08-21 04:43:03 +00:00
|
|
|
|
2011-05-13 06:00:25 +00:00
|
|
|
/**
|
|
|
|
* @var string The syslog identifier
|
|
|
|
*/
|
2010-08-21 04:43:03 +00:00
|
|
|
protected $_ident;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new syslog logger.
|
|
|
|
*
|
2012-11-09 12:18:50 +00:00
|
|
|
* @link http://www.php.net/manual/function.openlog
|
2010-08-21 04:43:03 +00:00
|
|
|
*
|
2012-11-09 12:18:50 +00:00
|
|
|
* @param string $ident syslog identifier
|
|
|
|
* @param int $facility facility to log to
|
2010-08-21 04:43:03 +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-09 12:18:50 +00:00
|
|
|
* @param array $messages
|
2010-08-21 04:43:03 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function write(array $messages)
|
|
|
|
{
|
|
|
|
foreach ($messages as $message)
|
|
|
|
{
|
2011-05-13 06:00:25 +00:00
|
|
|
syslog($message['level'], $message['body']);
|
2012-11-09 12:18:50 +00:00
|
|
|
|
|
|
|
if (isset($message['additional']['exception']))
|
|
|
|
{
|
|
|
|
syslog(Log_Writer::$strace_level, $message['additional']['exception']->getTraceAsString());
|
|
|
|
}
|
2010-08-21 04:43:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Closes the syslog connection
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __destruct()
|
|
|
|
{
|
|
|
|
// Close connection to syslog
|
|
|
|
closelog();
|
|
|
|
}
|
|
|
|
|
2011-05-13 06:00:25 +00:00
|
|
|
} // End Kohana_Log_Syslog
|