-
Notifications
You must be signed in to change notification settings - Fork 0
/
megaErrorLog.php
382 lines (323 loc) · 12.8 KB
/
megaErrorLog.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
<?php
/**
* ________ _______ _______ ______ _______ __ ______ ______
* / |/ \ / \ / \ / \ / | / \ / \
* $$$$$$$$/ $$$$$$$ |$$$$$$$ |/$$$$$$ |$$$$$$$ | $$ | /$$$$$$ |/$$$$$$ |
* $$ |__ $$ |__$$ |$$ |__$$ |$$ | $$ |$$ |__$$ | $$ | $$ | $$ |$$ | _$$/
* $$ | $$ $$< $$ $$< $$ | $$ |$$ $$< $$ | $$ | $$ |$$ |/ |
* $$$$$/ $$$$$$$ |$$$$$$$ |$$ | $$ |$$$$$$$ | $$ | $$ | $$ |$$ |$$$$ |
* $$ |_____ $$ | $$ |$$ | $$ |$$ \__$$ |$$ | $$ | $$ |_____ $$ \__$$ |$$ \__$$ |
* $$ |$$ | $$ |$$ | $$ |$$ $$/ $$ | $$ | $$ |$$ $$/ $$ $$/
* $$$$$$$$/ $$/ $$/ $$/ $$/ $$$$$$/ $$/ $$/ $$$$$$$$/ $$$$$$/ $$$$$$/
*
* __ __ __ _ _
* \ \ / / / \ / | /_\
* \ V / | () || | / _ \
* \_/ \__(_)_| /_/ \_\
*
* errorLog can help you for debuging script.
* author @yannchallet
* mail : [email protected]
*
*/
/**
*
* ___ ___ ___ _ _ ___ __ __ ___ ___ ___
* | \| __| _ ) | | |/ __| | \/ |/ _ \| \| __|
* | |) | _|| _ \ |_| | (_ | | |\/| | (_) | |) | _|
* |___/|___|___/\___/ \___| |_| |_|\___/|___/|___|
*
*
* 0=>Aucun traitement
* 1=>mode debug
* 2=>mode production (erreur dans log/error.log) erreur affichable pour _ERRORLOG_DEBUG_IP_
* 3=>mode production (erreur dans log/error.log)
*
*/
define('_ERRORLOG_DEBUG_MODE_', 1);
/**
*
* ___ ___ ___ ___ ___ _ _ ___
* |_ _| _ \ | \| __| _ ) | | |/ __|
* | || _/ | |) | _|| _ \ |_| | (_ |
* |___|_| |___/|___|___/\___/ \___|
*
*
* Adresse IP client autorisant l'affichage des erreurs
*
*/
define('_ERRORLOG_DEBUG_IP_', '127.0.0.1');
/**
*
* __ __ _ ___ _ ___ ___ ___ _ _ ___
* | \/ | /_\ |_ _| | | \| __| _ ) | | |/ __|
* | |\/| |/ _ \ | || |__ | |) | _|| _ \ |_| | (_ |
* |_| |_/_/ \_\___|____| |___/|___|___/\___/ \___|
*
*
* Adresse e-mail de l'administrateur
*
*
*/
define('_ERRORLOG_DEBUG_MAIL_', '[email protected]');
define('_ERRORLOG_DEBUG_SEND_ERROR_MAIL_', false);
/**
*
* _ ___ ___ ___ ___ _ ___
* | | / _ \ / __| | __|_ _| | | __|
* | |_| (_) | (_ | | _| | || |__| _|
* |____\___/ \___| |_| |___|____|___|
*
*
* _ERRORLOG_FILE_PATH_
* _ERRORLOG_FILE_DAY_
*/
define('_ERRORLOG_FILE_PATH_', 'log/');
define('_ERRORLOG_FILE_DAY_', true);
/**
*
* __ __ _ _ _ _____ ___ ___ ___ _____
* | \/ | /_\ | \| |_ _|_ _/ __| | _ )_ _|
* | |\/| |/ _ \| .` | | | | |\__ \ | _ \ | |
* |_| |_/_/ \_\_|\_| |_| |___|___/ |___/ |_|
*
*
* _ERRORLOG_MANTIS_ACTIVE_
* _ERRORLOG_MANTIS_USER_
* _ERRORLOG_MANTIS_PASSWORD_
* _ERRORLOG_MANTIS_SOAP_URL_
* _ERRORLOG_MANTIS_PROJECT_
* _ERRORLOG_MANTIS_CATEGORY_
*
*/
define('_ERRORLOG_MANTIS_ACTIVE_', true);
define('_ERRORLOG_MANTIS_USER_', '');
define('_ERRORLOG_MANTIS_PASSWORD_', '');
define('_ERRORLOG_MANTIS_SOAP_URL_', '');
define('_ERRORLOG_MANTIS_PROJECT_', '');
define('_ERRORLOG_MANTIS_CATEGORY_', '');
/**
*
* ___ ___ ___ ___ ___ _____ ___ __ __ ___ _ _ _____ ___
* | __| _ \ _ \/ _ \| _ \ |_ _| __| \/ | _ \ | /_\_ _| __|
* | _|| / / (_) | / | | | _|| |\/| | _/ |__ / _ \| | | _|
* |___|_|_\_|_\\___/|_|_\ |_| |___|_| |_|_| |____/_/ \_\_| |___|
*
*
* _ERRORLOG_TEMPLATE_ = html template {ERROR} is replaced by php error
*/
define('_ERRORLOG_TEMPLATE_FATAL_', '<div style="padding: 20px;background-color: #f44336;color: white;margin-bottom: 15px;"><span style="margin-left: 15px;color: white;font-weight: bold;float: right;font-size: 22px;line-height: 20px;cursor: pointer;transition: 0.3s;" onmouseover="this.style.color=\'black\';" onmouseout="this.style.color=\'\';" onclick="this.parentElement.style.display=\'none\';">×</span><b>FATAL : </b><br>{ERROR}</div>');
define('_ERRORLOG_TEMPLATE_WARNING_', '<div style="padding: 20px;background-color: #ff9800;color: white;margin-bottom: 15px;"><span style="margin-left: 15px;color: white;font-weight: bold;float: right;font-size: 22px;line-height: 20px;cursor: pointer;transition: 0.3s;" onmouseover="this.style.color=\'black\';" onmouseout="this.style.color=\'\';" onclick="this.parentElement.style.display=\'none\';">×</span><b>WARNING : </b><br>{ERROR}</div>');
define('_ERRORLOG_TEMPLATE_NOTICE_', '<div style="padding: 20px;background-color: #2196F3;color: white;margin-bottom: 15px;"><span style="margin-left: 15px;color: white;font-weight: bold;float: right;font-size: 22px;line-height: 20px;cursor: pointer;transition: 0.3s;" onmouseover="this.style.color=\'black\';" onmouseout="this.style.color=\'\';" onclick="this.parentElement.style.display=\'none\';">×</span><b>NOTICE : </b><br>{ERROR}</div>');
/**
*
* _ _ ___ ___ ___ __ __ ___ ___ ___ _ ___ ___
* | | | / __| __| _ \ | \/ | __/ __/ __| /_\ / __| __|
* | |_| \__ \ _|| / | |\/| | _|\__ \__ \/ _ \ (_ | _|
* \___/|___/___|_|_\ |_| |_|___|___/___/_/ \_\___|___|
*
*
* _ERRORLOG_FATAL_USER_MESSAGE_
* _ERRORLOG_MANTIS_USER_
*
*/
define('_ERRORLOG_FATAL_USER_MESSAGE_', true);
define('_ERRORLOG_FATAL_USER_MESSAGE_TEMPLATE_', '<div style="padding: 10px;background-color: #f44336;color: white;margin: 0px 0px 15px 0px;position: absolute;top: 0px;left: 0px;width: 100%;"><span style="margin-right: 15px;color: white;font-weight: bold;font-size: 22px;line-height: 20px;cursor: pointer;transition: 0.3s;" onclick="this.parentElement.style.display=\'none\';">×</span>Une erreur c\'est produite l\'administrateur en a été informé.Vous pouvez envoyez des précisions a cette adresse : '._ERRORLOG_DEBUG_MAIL_.'</div>');
/**
*
* _____ _______ ___ _ ___ ___ _____ ___ ___ _ _ ___
* | __\ \/ /_ _| _ \ /_\ / _ \| _ \_ _|_ _/ _ \| \| / __|
* | _| > < | | | / / _ \ | (_) | _/ | | | | (_) | .` \__ \
* |___/_/\_\ |_| |_|_\/_/ \_\ \___/|_| |_| |___\___/|_|\_|___/
*
*
* _ERRORLOG_NOT_INTERNAL_HANDLER_
* true, don't execute PHP internal error handler
*
* _ERRORLOG_FORCE_DISPLAY_ERROR_GET_
* empty : not active, string : $_GET variable to force error display
*
*/
define('_ERRORLOG_NOT_INTERNAL_HANDLER_', false);
define('_ERRORLOG_FORCE_DISPLAY_ERROR_GET_', '');
/**
* Class Error Log
*/
class ErrorLog
{
private static $_dispError = false;
static public function set()
{
if (_ERRORLOG_DEBUG_MODE_ > 0 && _ERRORLOG_DEBUG_MODE_ < 4) {
$error_handler = set_error_handler(array('ErrorLog', 'ErrorHandler'));
register_shutdown_function(array('ErrorLog', 'shutdown'));
}
switch (_ERRORLOG_DEBUG_MODE_) {
case 1:
if (PHP_VERSION_ID < 50400) error_reporting (E_ALL | E_STRICT);
else error_reporting (E_ALL);
self::initDispError();
ini_set('display_errors', false);
ini_set('html_errors', false);
ini_set('display_startup_errors',false);
self::initLogFolder();
self::initErrorLogFile();
ini_set('error_prepend_string','<span style="color: red;">');
ini_set('error_append_string','<br /></span>');
ini_set('ignore_repeated_errors', false);
break;
case 2:
if (PHP_VERSION_ID < 50400) error_reporting (E_ALL | E_STRICT);
else error_reporting (E_ALL);
self::initLogFolder();
ini_set('display_errors', false);
ini_set('html_errors', false);
ini_set('display_startup_errors',false);
self::initErrorLogFile();
self::initDispError();
ini_set('error_prepend_string','<span style="color: red;">');
ini_set('error_append_string','</span>');
ini_set('ignore_repeated_errors', true);
break;
case 3:
if (PHP_VERSION_ID < 50400) error_reporting (E_ALL | E_STRICT);
else error_reporting (E_ALL);
self::initLogFolder();
ini_set('display_errors', false);
ini_set('html_errors', false);
ini_set('display_startup_errors',false);
self::initErrorLogFile();
self::initDispError();
ini_set('ignore_repeated_errors', true);
break;
default:
if (PHP_VERSION_ID < 50400) error_reporting (E_ALL | E_STRICT);
else error_reporting (E_ALL);
ini_set('display_errors', false);
ini_set('html_errors', false);
ini_set('display_startup_errors',false);
ini_set('log_errors', false);
}
}
private static function initLogFolder()
{
if (is_dir(_ERRORLOG_FILE_PATH_)) {
if (!is_writable(_ERRORLOG_FILE_PATH_)) {
echo str_replace('{ERROR}', _ERRORLOG_FILE_PATH_.' is not writable', _ERRORLOG_TEMPLATE_WARNING_);
}
} else {
if (self::$_dispError) {
echo str_replace('{ERROR}', _ERRORLOG_FILE_PATH_.' is not a directory', _ERRORLOG_TEMPLATE_WARNING_);
}
}
}
private static function initDispError()
{
if ((_ERRORLOG_DEBUG_MODE_ == 1)
|| (_ERRORLOG_DEBUG_MODE_ == 2 && $_SERVER["REMOTE_ADDR"] == _ERRORLOG_DEBUG_IP_)
|| (_ERRORLOG_FORCE_DISPLAY_ERROR_GET_ != '' && isset($_GET[_ERRORLOG_FORCE_DISPLAY_ERROR_GET_]))) {
self::$_dispError = true;
}
}
private static function initErrorLogFile()
{
ini_set('log_errors', true);
if (_ERRORLOG_FILE_PATH_ !== false) {
if (_ERRORLOG_FILE_DAY_) {
$fileName = _ERRORLOG_FILE_PATH_ . date('Y-m-d').'_error.log';
} else {
$fileName = _ERRORLOG_FILE_PATH_ . 'error.log';
}
ini_set('error_log', $fileName);
}
}
private static function sendToMantisBT($errno, $errstr, $errfile, $errline)
{
$message = "ERROR [$errno] $errstr\n
Error on line $errline in file $errfile, PHP " . PHP_VERSION . " (" . PHP_OS . ")\n";
if (_ERRORLOG_MANTIS_ACTIVE_ && _ERRORLOG_DEBUG_MODE_ > 1) {
switch ($errno) {
case E_USER_ERROR:
$type = 'FATAL';
$severity = 80;
break;
case E_USER_WARNING:
$type = 'WARNING';
$severity = 60;
break;
case E_USER_NOTICE:
$type = 'NOTICE';
$severity = 50;
break;
default:
$type = 'FATAL';
$severity = 80;
break;
}
try {
$client = new SoapClient(_ERRORLOG_MANTIS_SOAP_URL_);
$issue = array (
'summary' => $errstr,
'description' => $type.'::'.$message,
'project'=>array('name'=>_ERRORLOG_MANTIS_PROJECT_),
'category'=>_ERRORLOG_MANTIS_CATEGORY_,
'platform'=>'PHP '.PHP_VERSION,
'os'=>PHP_OS,
'os_build'=>php_uname('r'),
'severity'=>array('id'=>$severity),
'status'=>array('id'=>40),
'additional_information'=>"Imported from ERRORLOG - ".date('d.m.Y H:i:s')."\n".php_uname()
);
$issue_id = $client->mc_issue_add(_ERRORLOG_MANTIS_USER_, _ERRORLOG_MANTIS_PASSWORD_, $issue);
var_dump($issue_id);
}
catch (SoapFault $exception) {
echo $exception;
error_log($exception);
}
}
}
public static function ErrorHandler($errno, $errstr, $errfile, $errline)
{
$message = "<b>ERROR</b> [$errno] $errstr<br />\n
Error on line $errline in file $errfile, PHP " . PHP_VERSION . " (" . PHP_OS . ")<br />\n";
switch ($errno) {
case E_USER_ERROR:
if (self::$_dispError) {
echo str_replace('{ERROR}', $message, _ERRORLOG_TEMPLATE_FATAL_);
}
break;
case E_USER_WARNING:
if (self::$_dispError) {
echo str_replace('{ERROR}', $message, _ERRORLOG_TEMPLATE_WARNING_);
}
break;
case E_USER_NOTICE:
if (self::$_dispError) {
echo str_replace('{ERROR}', $message, _ERRORLOG_TEMPLATE_NOTICE_);
}
break;
default:
if (self::$_dispError) {
echo str_replace('{ERROR}', $message, _ERRORLOG_TEMPLATE_FATAL_);
}
break;
}
self::sendToMantisBT($errno, $errstr, $errfile, $errline);
if ($errno == E_USER_ERROR) {
if (_ERRORLOG_FATAL_USER_MESSAGE_ && _ERRORLOG_DEBUG_MODE_ > 1) {
echo _ERRORLOG_FATAL_USER_MESSAGE_TEMPLATE_;
}
exit(1);
}
/* Don't execute PHP internal error handler */
return _ERRORLOG_NOT_INTERNAL_HANDLER_;
}
public static function shutdown()
{
if (_ERRORLOG_DEBUG_MODE_ == 1) {
echo '<div style="padding: 10px;background-color: #f44336;color: white;margin: 0px 0px 15px 0px;position: absolute;top: 0px;left: 0px;width: 100%;"><span style="margin-right: 15px;color: white;font-weight: bold;font-size: 22px;line-height: 20px;cursor: pointer;transition: 0.3s;" onclick="this.parentElement.style.display=\'none\';">×</span>Mode debug activé, si vous voyer ce Bandeau merci de contacter le webmaster : '._ERRORLOG_DEBUG_MAIL_.'</div>', PHP_EOL;
}
}
}
ErrorLog::set();