Syslog::process()   A
last analyzed

Complexity

Conditions 1
Paths 3

Size

Total Lines 18
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 18
ccs 13
cts 13
cp 1
rs 9.7998
cc 1
nc 3
nop 1
crap 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
use function closelog;
17
use function openlog;
18
use function strtr;
19
20
/**
21
 * System log.
22
 *
23
 * @link http://www.php.net/manual/en/function.openlog.php
24
 */
25
class Syslog extends Processor
26 1
{
27
    protected string $format = '[levelname] message';
28
29 1
    protected function process(array $message): void
30 1
    {
31 1
        $levels = [
32 1
            Logger::DEBUG     => LOG_DEBUG,
33 1
            Logger::INFO      => LOG_INFO,
34 1
            Logger::NOTICE    => LOG_NOTICE,
35 1
            Logger::WARNING   => LOG_WARNING,
36 1
            Logger::ERROR     => LOG_ERR,
37
            Logger::CRITICAL  => LOG_CRIT,
38
            Logger::ALERT     => LOG_ALERT,
39
            Logger::EMERGENCY => LOG_EMERG
40 1
        ];
41 1
42 1
        try {
43 1
            openlog('', LOG_CONS, LOG_USER);
44
            \syslog($levels[$message['level']] ?? LOG_DEBUG, strtr($this->format, $message));
45 1
        } finally {
46
            closelog();
47
        }
48
    }
49
}
50