PageRenderTime 182ms CodeModel.GetById 100ms app.highlight 2ms RepoModel.GetById 79ms app.codeStats 0ms

/system/classes/Kohana/Log/Syslog.php

https://bitbucket.org/chrispiechowicz/zepto
PHP | 65 lines | 24 code | 7 blank | 34 comment | 1 complexity | 6b812885cbe844bcdf31f312b450c0d8 MD5 | raw file
 1<?php defined('SYSPATH') OR die('No direct script access.');
 2/**
 3 * Syslog log writer.
 4 *
 5 * @package    Kohana
 6 * @category   Logging
 7 * @author     Jeremy Bush
 8 * @copyright  (c) 2012 Kohana Team
 9 * @license    http://kohanaframework.org/license
10 */
11class Kohana_Log_Syslog extends Log_Writer {
12
13	/**
14	 * @var  string  The syslog identifier
15	 */
16	protected $_ident;
17
18	/**
19	 * Creates a new syslog logger.
20	 *
21	 * @link    http://www.php.net/manual/function.openlog
22	 *
23	 * @param   string  $ident      syslog identifier
24	 * @param   int     $facility   facility to log to
25	 * @return  void
26	 */
27	public function __construct($ident = 'KohanaPHP', $facility = LOG_USER)
28	{
29		$this->_ident = $ident;
30
31		// Open the connection to syslog
32		openlog($this->_ident, LOG_CONS, $facility);
33	}
34
35	/**
36	 * Writes each of the messages into the syslog.
37	 *
38	 * @param   array   $messages
39	 * @return  void
40	 */
41	public function write(array $messages)
42	{
43		foreach ($messages as $message)
44		{
45			syslog($message['level'], $message['body']);
46
47			if (isset($message['additional']['exception']))
48			{
49				syslog(Log_Writer::$strace_level, $message['additional']['exception']->getTraceAsString());
50			}
51		}
52	}
53
54	/**
55	 * Closes the syslog connection
56	 *
57	 * @return  void
58	 */
59	public function __destruct()
60	{
61		// Close connection to syslog
62		closelog();
63	}
64
65} // End Kohana_Log_Syslog