Syslog   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 72
rs 10
c 0
b 0
f 0
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A log() 0 3 1
B setOptions() 0 31 6
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * Balloon
7
 *
8
 * @author      Raffael Sahli <[email protected]>
9
 * @copyright   Copryright (c) 2012-2017 gyselroth GmbH (https://gyselroth.com)
10
 * @license     GPL-3.0 https://opensource.org/licenses/GPL-3.0
11
 */
12
13
namespace Micro\Log\Adapter;
14
15
use Micro\Log\Log;
16
17
class Syslog extends AbstractAdapter
18
{
19
    /**
20
     * Syslog ident.
21
     *
22
     * @var string
23
     */
24
    protected $ident;
25
26
    /**
27
     * Option.
28
     *
29
     * @var int
30
     */
31
    protected $option = LOG_PID;
32
33
    /**
34
     * Facility.
35
     *
36
     * @var int
37
     */
38
    protected $facility = LOG_SYSLOG;
39
40
    /**
41
     * Set options.
42
     *
43
     * @return AdapterInterface
44
     */
45
    public function setOptions(? Iterable $config = null): AdapterInterface
46
    {
47
        if (null === $config) {
48
            return $this;
49
        }
50
51
        foreach ($config as $option => $value) {
52
            switch ($option) {
53
                case 'ident':
54
                    $this->ident = (string) $value;
55
                    unset($config[$option]);
56
57
                break;
58
                case 'option':
59
                    $this->option = (int) (string) $value;
60
                    unset($config[$option]);
61
62
                break;
63
                case 'facility':
64
                    $this->facility = (int) (string) $value;
65
                    unset($config[$option]);
66
67
                break;
68
            }
69
        }
70
71
        parent::setOptions($config);
72
73
        openlog($this->ident, $this->option, $this->facility);
74
75
        return $this;
76
    }
77
78
    /**
79
     * Log.
80
     *
81
     * @param string $level
82
     * @param string $message
83
     *
84
     * @return bool
85
     */
86
    public function log(string $level, string $message): bool
87
    {
88
        return syslog(Log::PRIORITIES[$level], $message);
89
    }
90
}
91