ToSyslog   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 2
A singleton() 0 6 3
A output() 0 3 2
A __destruct() 0 3 1
1
<?php
2
/**
3
 * Třída pro logování.
4
 *
5
 * @author    Vitex <[email protected]>
6
 * @copyright 2009-2019 [email protected] (G)
7
 */
8
9
namespace Ease\Logger;
10
11
/**
12
 * Log to syslog.
13
 *
14
 * @author    Vitex <[email protected]>
15
 * @copyright 2009-2019 [email protected] (G)
16
 */
17
class ToSyslog extends ToStd implements Loggingable
18
{
19
    /**
20
     * Předvolená metoda logování.
21
     *
22
     * @var string
23
     */
24
    public $logType = 'syslog';
25
26
    /**
27
     * Saves obejct instace (singleton...).
28
     */
29
    private static $instance = null;
30
31
    /**
32
     * Logovací třída.
33
     *
34
     * @param string $logName syslog log source identifier
35
     */
36
    public function __construct($logName = null)
37
    {
38
        if (!empty($logName)) {
39
            openlog($logName, constant('LOG_NDELAY'), constant('LOG_USER'));
40
        }
41
    }
42
43
    /**
44
     * Obtain instance of Syslog loger
45
     * 
46
     * @return ToSyslog
47
     */
48
    public static function singleton()
49
    {
50
        if (!isset(self::$instance)) {
51
                self::$instance = new self(defined('EASE_APPNAME') ? constant('EASE_APPNAME') :  'EaseFramework');
52
        }
53
        return self::$instance;
54
    }
55
56
    /**
57
     * Output logline to syslog/messages by its type
58
     *
59
     * @param string $type    message type 'error' or anything else
60
     * @param string $logLine message to output
61
     */
62
    public function output($type, $logLine)
63
    {
64
        return syslog($type == 'error' ? constant('LOG_ERR') : constant('LOG_INFO'), $this->finalizeMessage($logLine));
65
    }
66
67
    /**
68
     * Uzavře chybové soubory.
69
     * 
70
     * @return boolean syslog close status
71
     */
72
    public function __destruct()
73
    {
74
        return closelog();
75
    }
76
}
77