scratch – Blame information for rev 115

Subversion Repositories:
Rev:
Rev Author Line No. Line
115 office 1 <?php
2  
3 /*
4 * This file is part of the Monolog package.
5 *
6 * (c) Jordi Boggiano <j.boggiano@seld.be>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11  
12 namespace Monolog\Handler;
13  
14 use Monolog\Logger;
15  
16 /**
17 * Logs to syslog service.
18 *
19 * usage example:
20 *
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);
26 *
27 * @author Sven Paulus <sven@karlsruhe.org>
28 */
29 class SyslogHandler extends AbstractSyslogHandler
30 {
31 protected $ident;
32 protected $logopts;
33  
34 /**
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
40 */
41 public function __construct($ident, $facility = LOG_USER, $level = Logger::DEBUG, $bubble = true, $logopts = LOG_PID)
42 {
43 parent::__construct($facility, $level, $bubble);
44  
45 $this->ident = $ident;
46 $this->logopts = $logopts;
47 }
48  
49 /**
50 * {@inheritdoc}
51 */
52 public function close()
53 {
54 closelog();
55 }
56  
57 /**
58 * {@inheritdoc}
59 */
60 protected function write(array $record)
61 {
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.'"');
64 }
65 syslog($this->logLevels[$record['level']], (string) $record['formatted']);
66 }
67 }