1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the sj-i/php-profiler package. |
5
|
|
|
* |
6
|
|
|
* (c) sji <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace PhpProfiler\Lib\Log; |
15
|
|
|
|
16
|
|
|
use PhpProfiler\Lib\Log\StateCollector\NullStateCollector; |
17
|
|
|
use PhpProfiler\Lib\Log\StateCollector\StateCollector; |
18
|
|
|
use Psr\Log\LoggerInterface; |
|
|
|
|
19
|
|
|
use Psr\Log\LogLevel; |
|
|
|
|
20
|
|
|
use Psr\Log\NullLogger; |
|
|
|
|
21
|
|
|
|
22
|
|
|
final class Log |
23
|
|
|
{ |
24
|
|
|
public const LOG_LEVELS = [ |
25
|
|
|
LogLevel::EMERGENCY, |
26
|
|
|
LogLevel::ALERT, |
27
|
|
|
LogLevel::CRITICAL, |
28
|
|
|
LogLevel::ERROR, |
29
|
|
|
LogLevel::WARNING, |
30
|
|
|
LogLevel::NOTICE, |
31
|
|
|
LogLevel::INFO, |
32
|
|
|
LogLevel::DEBUG, |
33
|
|
|
]; |
34
|
|
|
|
35
|
|
|
private static ?LoggerInterface $logger = null; |
36
|
|
|
private static ?StateCollector $state_collector = null; |
37
|
|
|
|
38
|
|
|
public static function initializeLogger( |
39
|
|
|
LoggerInterface $logger, |
40
|
|
|
StateCollector $state_collector, |
41
|
|
|
): void { |
42
|
|
|
self::$logger = $logger; |
43
|
|
|
self::$state_collector = $state_collector; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public static function getLogger(): LoggerInterface |
47
|
|
|
{ |
48
|
|
|
if (!isset(self::$logger)) { |
49
|
|
|
self::$logger = new NullLogger(); |
50
|
|
|
} |
51
|
|
|
return self::$logger; |
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public static function getCollector(): StateCollector |
55
|
|
|
{ |
56
|
|
|
if (!isset(self::$state_collector)) { |
57
|
|
|
self::$state_collector = new NullStateCollector(); |
58
|
|
|
} |
59
|
|
|
return self::$state_collector; |
|
|
|
|
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param value-of<self::LOG_LEVELS> $level |
|
|
|
|
64
|
|
|
*/ |
65
|
|
|
public static function log(string $level, string $message, array $context = []): void |
66
|
|
|
{ |
67
|
|
|
self::getLogger()->log($level, $message, $context + self::getCollector()->collect()); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public static function emergency(string $message, array $context = []): void |
71
|
|
|
{ |
72
|
|
|
self::log(LogLevel::EMERGENCY, $message, $context); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public static function alert(string $message, array $context = []): void |
76
|
|
|
{ |
77
|
|
|
self::log(LogLevel::ALERT, $message, $context); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public static function critical(string $message, array $context = []): void |
81
|
|
|
{ |
82
|
|
|
self::log(LogLevel::CRITICAL, $message, $context); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public static function error(string $message, array $context = []): void |
86
|
|
|
{ |
87
|
|
|
self::log(LogLevel::ERROR, $message, $context); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public static function warning(string $message, array $context = []): void |
91
|
|
|
{ |
92
|
|
|
self::log(LogLevel::WARNING, $message, $context); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public static function notice(string $message, array $context = []): void |
96
|
|
|
{ |
97
|
|
|
self::log(LogLevel::NOTICE, $message, $context); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public static function info(string $message, array $context = []): void |
101
|
|
|
{ |
102
|
|
|
self::log(LogLevel::INFO, $message, $context); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public static function debug(string $message, array $context = []): void |
106
|
|
|
{ |
107
|
|
|
self::log(LogLevel::DEBUG, $message, $context); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
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