Completed
Pull Request — master (#3)
by Mihail
10:52
created

Syslog   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 1
eloc 16
c 3
b 0
f 1
dl 0
loc 22
ccs 13
cts 13
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 18 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 string $format = '[levelname] message';
25
26 1
    protected function process(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);
0 ignored issues
show
Bug introduced by
null of type null is incompatible with the type string expected by parameter $prefix of openlog(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

40
            \openlog(/** @scrutinizer ignore-type */ null, LOG_CONS, LOG_USER);
Loading history...
41 1
            \syslog($levels[$message['level']] ?? LOG_DEBUG, \strtr($this->format, $message));
42 1
        } finally {
43 1
            \closelog();
44
        }
45 1
    }
46
}
47