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;
17 * Logs to syslog service.
21 * $log = new Logger('application');
22 * $syslog = new SyslogHandler('myfacility', 'local6');
23 * $formatter = new LineFormatter("%channel%.%level_name%: %message% %extra%");
24 * $syslog->setFormatter($formatter);
25 * $log->pushHandler($syslog);
27 * @author Sven Paulus <sven@karlsruhe.org>
29 class SyslogHandler extends AbstractSyslogHandler
35 * @param string $ident
36 * @param mixed $facility
37 * @param int $level The minimum logging level at which this handler will be triggered
38 * @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not
39 * @param int $logopts Option flags for the openlog() call, defaults to LOG_PID
41 public function __construct($ident, $facility = LOG_USER, $level = Logger::DEBUG, $bubble = true, $logopts = LOG_PID)
43 parent::__construct($facility, $level, $bubble);
45 $this->ident = $ident;
46 $this->logopts = $logopts;
52 public function close()
60 protected function write(array $record)
62 if (!openlog($this->ident, $this->logopts, $this->facility)) {
63 throw new \LogicException('Can\'t open syslog for ident "'.$this->ident.'" and facility "'.$this->facility.'"');
65 syslog($this->logLevels[$record['level']], (string) $record['formatted']);