1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Class to Rule message loggers. |
4
|
|
|
* |
5
|
|
|
* @author Vitex <[email protected]> |
6
|
|
|
* @copyright 2016 [email protected] (G) |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Ease\Logger; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Description of Regent |
13
|
|
|
* |
14
|
|
|
* @author vitex |
15
|
|
|
*/ |
16
|
|
|
class Regent extends \Ease\Atom |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* Saves obejct instace (singleton...). |
20
|
|
|
*/ |
21
|
|
|
private static $_instance = null; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Here to reach logger objects |
25
|
|
|
* @var array |
26
|
|
|
*/ |
27
|
|
|
public $loggers = []; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Hodnoty pro obarvování logu. |
31
|
|
|
* |
32
|
|
|
* @var array |
33
|
|
|
*/ |
34
|
|
|
public $logStyles = [ |
35
|
|
|
'notice' => 'color: black;', |
36
|
|
|
'success' => 'color: #2C5F23;', |
37
|
|
|
'message' => 'color: #2C5F23;', |
38
|
|
|
'warning' => 'color: #AB250E;', |
39
|
|
|
'error' => 'color: red;', |
40
|
|
|
'debug' => 'font-style: italic;', |
41
|
|
|
'report' => 'font-wight: bold;', |
42
|
|
|
'info' => 'color: blue;', |
43
|
|
|
]; |
44
|
|
|
|
45
|
|
|
public function __construct($logger = null) |
46
|
|
|
{ |
47
|
|
|
if (is_null($logger) && defined('EASE_LOGGER')) { |
48
|
|
|
$loggers = explode('|', constant('EASE_LOGGER')); |
49
|
|
|
} else { |
50
|
|
|
$loggers = empty($logger) ? ['syslog'] : [$logger]; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
foreach ($loggers as $logger) |
54
|
|
|
switch ($logger) { |
55
|
|
|
case 'console': |
56
|
|
|
$this->loggers[$logger] = ToConsole::singleton(); |
57
|
|
|
break; |
58
|
|
|
case 'syslog': |
59
|
|
|
$this->loggers[$logger] = ToSyslog::singleton(); |
60
|
|
|
break; |
61
|
|
|
case 'memory': |
62
|
|
|
$this->loggers[$logger] = ToMemory::singleton(); |
63
|
|
|
break; |
64
|
|
|
case 'email': |
65
|
|
|
$this->loggers[$logger] = ToEmail::singleton(); |
66
|
|
|
break; |
67
|
|
|
case 'std': |
68
|
|
|
$this->loggers[$logger] = ToStd::singleton(); |
69
|
|
|
break; |
70
|
|
|
case 'eventlog': |
71
|
|
|
$this->loggers[$logger] = ToEventlog::singleton(); |
72
|
|
|
break; |
73
|
|
|
default: |
74
|
|
|
if (class_exists($logger) && method_exists($logger, |
75
|
|
|
'singleton')) { |
76
|
|
|
$this->loggers[$logger] = $logger::singleton(); |
77
|
|
|
} else { |
78
|
|
|
$this->loggers[$logger] = ToFile::singleton($logger); |
|
|
|
|
79
|
|
|
} |
80
|
|
|
break; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function takeMessage() |
85
|
|
|
{ |
86
|
|
|
|
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Add Status Message to all registered loggers |
91
|
|
|
* |
92
|
|
|
* @param string $caller message provider |
93
|
|
|
* @param string $message message to log |
94
|
|
|
* @param string $type info|succes|warning|error|email|... |
95
|
|
|
*/ |
96
|
|
|
public function addToLog($caller, $message, $type = 'info') |
97
|
|
|
{ |
98
|
|
|
foreach ($this->loggers as $logger) { |
99
|
|
|
$logger->addToLog($caller, $message, $type); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Add Status Object to stack |
105
|
|
|
* |
106
|
|
|
* @param \Ease\Logger\Message $message |
107
|
|
|
* @param string $type |
108
|
|
|
* |
109
|
|
|
* @return int number of stored message |
110
|
|
|
*/ |
111
|
|
|
public function addStatusObject(Message $message, $type = 'info') |
|
|
|
|
112
|
|
|
{ |
113
|
|
|
$this->addToLog($message->caller, $message->body, $message->type); |
114
|
|
|
\Ease\Shared::instanced()->addStatusMessage($message->body, |
115
|
|
|
$message->type); |
116
|
|
|
return parent::addStatusMessage($message->body, $message->type); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Pri vytvareni objektu pomoci funkce singleton (ma stejne parametry, jako |
121
|
|
|
* konstruktor) se bude v ramci behu programu pouzivat pouze jedna jeho |
122
|
|
|
* instance (ta prvni). |
123
|
|
|
* |
124
|
|
|
* @link http://docs.php.net/en/language.oop5.patterns.html Dokumentace a |
125
|
|
|
* priklad |
126
|
|
|
*/ |
127
|
|
|
public static function singleton() |
128
|
|
|
{ |
129
|
|
|
if (!isset(self::$_instance)) { |
130
|
|
|
$class = __CLASS__; |
131
|
|
|
self::$_instance = new $class(); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
return self::$_instance; |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.