Passed
Push — master ( 51be4e...ecae65 )
by Vítězslav
04:27
created

ToSyslog   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Test Coverage

Coverage 75%

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 72
ccs 15
cts 20
cp 0.75
rs 10
c 0
b 0
f 0
wmc 8

4 Methods

Rating   Name   Duplication   Size   Complexity  
A singleton() 0 12 3
A __construct() 0 4 2
A __destruct() 0 3 1
A output() 0 9 2
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-2012 [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 1
    public function __construct($logName = null)
37
    {
38 1
        if (!empty($logName)) {
39 1
            openlog($logName, constant('LOG_NDELAY'), constant('LOG_USER'));
40
        }
41 1
    }
42
43
    /**
44
     * Pri vytvareni objektu pomoci funkce singleton (ma stejne parametry, jako
45
     * konstruktor) se bude v ramci behu programu pouzivat pouze jedna jeho
46
     * instance (ta prvni).
47
     *
48
     * @link http://docs.php.net/en/language.oop5.patterns.html Dokumentace a
49
     * priklad
50
     */
51 1
    public static function singleton()
52
    {
53 1
        if (!isset(self::$_instance)) {
54 1
            $class = __CLASS__;
55 1
            if (defined('EASE_APPNAME')) {
56
                self::$_instance = new $class(constant('EASE_APPNAME'));
57
            } else {
58 1
                self::$_instance = new $class('EaseFramework');
59
            }
60
        }
61
62 1
        return self::$_instance;
63
    }
64
65
    /**
66
     * Output logline to syslog/messages by its type
67
     *
68
     * @param string $type    message type 'error' or anything else
69
     * @param string $logLine message to output
70
     */
71 1
    public function output($type, $logLine)
72
    {
73
        switch ($type) {
74 1
            case 'error':
75 1
                syslog(LOG_ERR, $this->finalizeMessage($logLine));
76 1
                break;
77
            default:
78
                syslog(LOG_INFO, $this->finalizeMessage($logLine));
79
                break;
80
        }
81 1
    }
82
83
    /**
84
     * Uzavře chybové soubory.
85
     */
86
    public function __destruct()
87
    {
88
        closelog();
89
    }
90
}
91