1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Log to stdout/stderr |
4
|
|
|
* |
5
|
|
|
* @author Vitex <[email protected]> |
6
|
|
|
* @copyright 2009-2016 [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 ToStd extends ToMemory |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* Předvolená metoda logování. |
21
|
|
|
* |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
public $logType = 'stdout'; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* úroveň logování. |
28
|
|
|
* |
29
|
|
|
* @var string - silent,debug |
30
|
|
|
*/ |
31
|
|
|
public $logLevel = 'debug'; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Odkaz na vlastnící objekt. |
35
|
|
|
* |
36
|
|
|
* @var \Ease\Sand |
37
|
|
|
*/ |
38
|
|
|
public $parentObject = null; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Pole uložených zpráv. |
42
|
|
|
* |
43
|
|
|
* @var array |
44
|
|
|
*/ |
45
|
|
|
public $statusMessages = []; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* ID naposledy ulozene zpravy. |
49
|
|
|
* |
50
|
|
|
* @var int unsigned |
51
|
|
|
*/ |
52
|
|
|
private $messageID = 0; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Obecné konfigurace frameworku. |
56
|
|
|
* |
57
|
|
|
* @var Shared |
|
|
|
|
58
|
|
|
*/ |
59
|
|
|
public $easeShared = null; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* List of allready flushed messages. |
63
|
|
|
* |
64
|
|
|
* @var array |
65
|
|
|
*/ |
66
|
|
|
public $flushed = []; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Saves obejct instace (singleton...). |
70
|
|
|
*/ |
71
|
|
|
private static $_instance = null; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Log Name |
75
|
|
|
* |
76
|
|
|
* @var string |
77
|
|
|
*/ |
78
|
|
|
public $logName = null; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Logovací třída. |
82
|
|
|
* |
83
|
|
|
* @param string $logName symbolic name for log |
84
|
|
|
*/ |
85
|
|
|
public function __construct($logName = null) |
86
|
|
|
{ |
87
|
|
|
$this->logName = $logName; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Pri vytvareni objektu pomoci funkce singleton (ma stejne parametry, jako |
92
|
|
|
* konstruktor) se bude v ramci behu programu pouzivat pouze jedna jeho |
93
|
|
|
* instance (ta prvni). |
94
|
|
|
* |
95
|
|
|
* @link http://docs.php.net/en/language.oop5.patterns.html Dokumentace a |
96
|
|
|
* priklad |
97
|
|
|
*/ |
98
|
|
|
public static function singleton() |
99
|
|
|
{ |
100
|
|
|
if (!isset(self::$_instance)) { |
101
|
|
|
$class = __CLASS__; |
102
|
|
|
if (defined('EASE_APPNAME')) { |
103
|
|
|
self::$_instance = new $class(constant('EASE_APPNAME')); |
104
|
|
|
} else { |
105
|
|
|
self::$_instance = new $class('EaseFramework'); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
return self::$_instance; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Zapise zapravu do logu. |
115
|
|
|
* |
116
|
|
|
* @param string $caller název volajícího objektu |
117
|
|
|
* @param string $message zpráva |
118
|
|
|
* @param string $type typ zprávy (success|info|error|warning|*) |
119
|
|
|
* |
120
|
|
|
* @return null|boolean byl report zapsán ? |
121
|
|
|
*/ |
122
|
|
|
public function addToLog($caller, $message, $type = 'message') |
123
|
|
|
{ |
124
|
|
|
++$this->messageID; |
125
|
|
|
if (($this->logLevel == 'silent') && ($type != 'error')) { |
126
|
|
|
return; |
127
|
|
|
} |
128
|
|
|
if (($this->logLevel != 'debug') && ($type == 'debug')) { |
129
|
|
|
return; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
$this->statusMessages[$type][$this->messageID] = $message; |
133
|
|
|
|
134
|
|
|
$message = htmlspecialchars_decode(strip_tags(stripslashes($message))); |
135
|
|
|
|
136
|
|
|
$user = \Ease\Shared::user(); |
137
|
|
|
if( get_class($user) !== 'Ease\\Anonym' ) { |
138
|
|
|
if( method_exists($user, 'getUserName')){ |
139
|
|
|
$person = $user->getUserName(); |
140
|
|
|
} else { |
141
|
|
|
$person = $user->getObjectName(); |
142
|
|
|
} |
143
|
|
|
$caller = $person.' '.$caller; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
$logLine = ' `'.$caller.'` '.str_replace(['notice', 'message', 'debug', 'report', |
147
|
|
|
'error', 'warning', 'success', 'info', 'mail',], |
148
|
|
|
['**', '##', '@@', '::'], $type).' '.$message."\n"; |
149
|
|
|
if (!isset($this->logStyles[$type])) { |
150
|
|
|
$type = 'notice'; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
$this->output($type, $logLine); |
154
|
|
|
|
155
|
|
|
return true; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* Output logline to stderr/stdout by its type |
160
|
|
|
* |
161
|
|
|
* @param string $type message type 'error' or anything else |
162
|
|
|
* @param string $logLine message to output |
163
|
|
|
*/ |
164
|
|
|
public function output($type, $logLine) |
165
|
|
|
{ |
166
|
|
|
switch ($type) { |
167
|
|
|
case 'error': |
168
|
|
|
$stderr = fopen('php://stderr', 'w'); |
169
|
|
|
fwrite($stderr, $this->logName.': '.$logLine); |
|
|
|
|
170
|
|
|
fclose($stderr); |
|
|
|
|
171
|
|
|
break; |
172
|
|
|
default: |
173
|
|
|
$stdout = fopen('php://stdout', 'w'); |
174
|
|
|
fwrite($stdout, $this->logName.': '.$logLine); |
175
|
|
|
fclose($stdout); |
176
|
|
|
break; |
177
|
|
|
} |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* Oznamuje chybovou událost. |
182
|
|
|
* |
183
|
|
|
* @param string $caller název volající funkce, nebo objektu |
184
|
|
|
* @param string $message zpráva |
185
|
|
|
* @param mixed $objectData data k zaznamenání |
186
|
|
|
*/ |
187
|
|
|
public function error($caller, $message, $objectData = null) |
188
|
|
|
{ |
189
|
|
|
if (!is_null($objectData)) { |
190
|
|
|
$message .= print_r($objectData, true); |
191
|
|
|
} |
192
|
|
|
$this->addToLog($caller, $message, 'error'); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* Last message check/modify point before output |
197
|
|
|
* |
198
|
|
|
* @param string $messageRaw |
199
|
|
|
* |
200
|
|
|
* @return string ready to use message |
201
|
|
|
*/ |
202
|
|
|
public function finalizeMessage($messageRaw) |
203
|
|
|
{ |
204
|
|
|
return trim($messageRaw).PHP_EOL; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* Flush Messages. |
209
|
|
|
* |
210
|
|
|
* @param string $caller |
211
|
|
|
* |
212
|
|
|
* @return int how many messages was flushed |
213
|
|
|
*/ |
214
|
|
|
public function flush($caller = null) |
215
|
|
|
{ |
216
|
|
|
$flushed = 0; |
217
|
|
|
if (count($this->statusMessages)) { |
218
|
|
|
foreach ($this->statusMessages as $type => $messages) { |
219
|
|
|
foreach ($messages as $messageID => $message) { |
220
|
|
|
if (!isset($this->flushed[$type][$messageID])) { |
221
|
|
|
$this->addToLog($caller, $message, $type); |
222
|
|
|
$this->flushed[$type][$messageID] = true; |
223
|
|
|
++$flushed; |
224
|
|
|
} |
225
|
|
|
} |
226
|
|
|
} |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
return $flushed; |
230
|
|
|
} |
231
|
|
|
} |
232
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths