|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace LE_ACME2\Utilities; |
|
4
|
|
|
|
|
5
|
|
|
use LE_ACME2\SingletonTrait; |
|
6
|
|
|
|
|
7
|
|
|
class Logger { |
|
8
|
|
|
|
|
9
|
|
|
use SingletonTrait; |
|
10
|
|
|
|
|
11
|
|
|
const LEVEL_DISABLED = 0; |
|
12
|
|
|
const LEVEL_INFO = 1; |
|
13
|
|
|
const LEVEL_DEBUG = 2; |
|
14
|
|
|
|
|
15
|
|
|
private function __construct() {} |
|
16
|
|
|
|
|
17
|
|
|
protected $_desiredLevel = self::LEVEL_DISABLED; |
|
18
|
|
|
|
|
19
|
|
|
public function setDesiredLevel(int $desiredLevel) { |
|
20
|
|
|
$this->_desiredLevel = $desiredLevel; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** @var \Psr\Log\LoggerInterface|null $_psrLogger */ |
|
|
|
|
|
|
24
|
|
|
private $_psrLogger = null; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @param \Psr\Log\LoggerInterface|null $psrLogger |
|
28
|
|
|
*/ |
|
29
|
|
|
public function setPSRLogger($psrLogger) { |
|
30
|
|
|
$this->_psrLogger = $psrLogger; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @param int $level |
|
35
|
|
|
* @param string $message |
|
36
|
|
|
* @param array $data |
|
37
|
|
|
*/ |
|
38
|
|
|
public function add(int $level, string $message, array $data = array()) { |
|
39
|
|
|
|
|
40
|
|
|
if($level > $this->_desiredLevel) |
|
41
|
|
|
return; |
|
42
|
|
|
|
|
43
|
|
|
if($this->_psrLogger) { |
|
44
|
|
|
|
|
45
|
|
|
if($level == self::LEVEL_INFO) { |
|
46
|
|
|
$this->_psrLogger->info($message, $data); |
|
47
|
|
|
return; |
|
48
|
|
|
} |
|
49
|
|
|
if($level == self::LEVEL_DEBUG) { |
|
50
|
|
|
$this->_psrLogger->debug($message, $data); |
|
51
|
|
|
return; |
|
52
|
|
|
} |
|
53
|
|
|
throw new \RuntimeException('Missing PSR Logger support for level: ' . $level); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
$e = new \Exception(); |
|
57
|
|
|
$trace = $e->getTrace(); |
|
58
|
|
|
unset($trace[0]); |
|
59
|
|
|
|
|
60
|
|
|
$output = '<b>' . date('d-m-Y H:i:s') . ': ' . $message . '</b><br>' . "\n"; |
|
61
|
|
|
|
|
62
|
|
|
if($this->_desiredLevel == self::LEVEL_DEBUG) { |
|
63
|
|
|
|
|
64
|
|
|
$step = 0; |
|
65
|
|
|
foreach ($trace as $traceItem) { |
|
66
|
|
|
|
|
67
|
|
|
if(!isset($traceItem['class']) || !isset($traceItem['function'])) { |
|
68
|
|
|
continue; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
$output .= 'Trace #' . $step . ': ' . $traceItem['class'] . '::' . $traceItem['function'] . '<br/>' . "\n"; |
|
72
|
|
|
$step++; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
if ((is_array($data) && count($data) > 0) || !is_array($data)) |
|
76
|
|
|
$output .= "\n" .'<br/>Data:<br/>' . "\n" . '<pre>' . var_export($data, true) . '</pre>'; |
|
77
|
|
|
|
|
78
|
|
|
$output .= '<br><br>' . "\n\n"; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
if(PHP_SAPI == 'cli') { |
|
82
|
|
|
|
|
83
|
|
|
$output = strip_tags($output); |
|
84
|
|
|
} |
|
85
|
|
|
echo $output; |
|
86
|
|
|
} |
|
87
|
|
|
} |
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