123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?php
- /**
- * Syslog log writer.
- *
- * @package KO7
- * @category Logging
- * @author Jeremy Bush
- * @copyright (c) 2007-2016 Kohana Team
- * @copyright (c) since 2016 Koseven Team
- * @license https://koseven.dev/LICENSE
- */
- class KO7_Log_Syslog extends Log_Writer {
- /**
- * @var string The syslog identifier
- */
- protected $_ident;
- /**
- * Creates a new syslog logger.
- *
- * @link http://www.php.net/manual/function.openlog
- *
- * @param string $ident syslog identifier
- * @param int $facility facility to log to
- * @return void
- */
- public function __construct($ident = 'KO7PHP', $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.
- *
- * @param array $messages
- * @return void
- */
- public function write(array $messages)
- {
- foreach ($messages as $message)
- {
- syslog($message['level'], $message['body']);
- if (isset($message['additional']['exception']))
- {
- syslog(Log_Writer::$strace_level, $message['additional']['exception']->getTraceAsString());
- }
- }
- }
- /**
- * Closes the syslog connection
- *
- * @return void
- */
- public function __destruct()
- {
- // Close connection to syslog
- closelog();
- }
- }
|