4 * This file is part of the Monolog package.
6 * (c) Jordi Boggiano <j.boggiano@seld.be>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Monolog\Handler;
15 use Monolog\Formatter\LineFormatter;
18 * Common syslog functionality
20 abstract class AbstractSyslogHandler extends AbstractProcessingHandler
25 * Translates Monolog log levels to syslog log priorities.
27 protected $logLevels = array(
28 Logger::DEBUG => LOG_DEBUG,
29 Logger::INFO => LOG_INFO,
30 Logger::NOTICE => LOG_NOTICE,
31 Logger::WARNING => LOG_WARNING,
32 Logger::ERROR => LOG_ERR,
33 Logger::CRITICAL => LOG_CRIT,
34 Logger::ALERT => LOG_ALERT,
35 Logger::EMERGENCY => LOG_EMERG,
39 * List of valid log facility names.
41 protected $facilities = array(
43 'authpriv' => LOG_AUTHPRIV,
45 'daemon' => LOG_DAEMON,
50 'syslog' => LOG_SYSLOG,
56 * @param mixed $facility
57 * @param int $level The minimum logging level at which this handler will be triggered
58 * @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not
60 public function __construct($facility = LOG_USER, $level = Logger::DEBUG, $bubble = true)
62 parent::__construct($level, $bubble);
64 if (!defined('PHP_WINDOWS_VERSION_BUILD')) {
65 $this->facilities['local0'] = LOG_LOCAL0;
66 $this->facilities['local1'] = LOG_LOCAL1;
67 $this->facilities['local2'] = LOG_LOCAL2;
68 $this->facilities['local3'] = LOG_LOCAL3;
69 $this->facilities['local4'] = LOG_LOCAL4;
70 $this->facilities['local5'] = LOG_LOCAL5;
71 $this->facilities['local6'] = LOG_LOCAL6;
72 $this->facilities['local7'] = LOG_LOCAL7;
74 $this->facilities['local0'] = 128; // LOG_LOCAL0
75 $this->facilities['local1'] = 136; // LOG_LOCAL1
76 $this->facilities['local2'] = 144; // LOG_LOCAL2
77 $this->facilities['local3'] = 152; // LOG_LOCAL3
78 $this->facilities['local4'] = 160; // LOG_LOCAL4
79 $this->facilities['local5'] = 168; // LOG_LOCAL5
80 $this->facilities['local6'] = 176; // LOG_LOCAL6
81 $this->facilities['local7'] = 184; // LOG_LOCAL7
84 // convert textual description of facility to syslog constant
85 if (array_key_exists(strtolower($facility), $this->facilities)) {
86 $facility = $this->facilities[strtolower($facility)];
87 } elseif (!in_array($facility, array_values($this->facilities), true)) {
88 throw new \UnexpectedValueException('Unknown facility value "'.$facility.'" given');
91 $this->facility = $facility;
97 protected function getDefaultFormatter()
99 return new LineFormatter('%channel%.%level_name%: %message% %context% %extra%');