Passed
Pull Request — master (#2)
by Mihail
03:21
created

Syslog::update()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 6
rs 10
cc 2
nc 2
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Koded package.
5
 *
6
 * (c) Mihail Binev <[email protected]>
7
 *
8
 * Please view the LICENSE distributed with this source code
9
 * for the full copyright and license information.
10
 *
11
 */
12
13
namespace Koded\Logging\Processors;
14
15
use Koded\Logging\Logger;
16
17
/**
18
 * System log.
19
 *
20
 * @link http://www.php.net/manual/en/function.openlog.php
21
 */
22
class Syslog extends Processor
23
{
24
    protected $format = '[levelname] message';
25
26 1
    protected function parse(array $message): void
27
    {
28
        $levels = [
29 1
            Logger::DEBUG     => LOG_DEBUG,
30 1
            Logger::INFO      => LOG_INFO,
31 1
            Logger::NOTICE    => LOG_NOTICE,
32 1
            Logger::WARNING   => LOG_WARNING,
33 1
            Logger::ERROR     => LOG_ERR,
34 1
            Logger::CRITICAL  => LOG_CRIT,
35 1
            Logger::ALERT     => LOG_ALERT,
36 1
            Logger::EMERGENCY => LOG_EMERG
37
        ];
38
39
        try {
40 1
            openlog(null, LOG_CONS, LOG_USER);
41 1
            syslog($levels[$message['level']] ?? LOG_DEBUG, strtr($this->format, $message));
42 1
        } finally {
43 1
            closelog();
44
        }
45 1
    }
46
}
47