1 | <?php |
||
21 | class Logger extends Component implements LoggerInterface |
||
22 | { |
||
23 | |||
24 | /** |
||
25 | * The Yii2 category to use when logging |
||
26 | * |
||
27 | * @var string |
||
28 | */ |
||
29 | public $category = 'PSR-3'; |
||
30 | |||
31 | /** |
||
32 | * The logger |
||
33 | * |
||
34 | * @var null|YiiLogger |
||
35 | */ |
||
36 | public $logger; |
||
37 | |||
38 | /** |
||
39 | * The default level to use when an arbitrary level is used. |
||
40 | * |
||
41 | * @var string |
||
42 | */ |
||
43 | public $level = YiiLogger::LEVEL_INFO; |
||
44 | |||
45 | /** |
||
46 | * The PSR-3 to Yii2 log level map |
||
47 | * |
||
48 | * @var array |
||
49 | */ |
||
50 | public $map = [ |
||
51 | 'emergency' => YiiLogger::LEVEL_ERROR, |
||
52 | 'alert' => YiiLogger::LEVEL_ERROR, |
||
53 | 'critical' => YiiLogger::LEVEL_ERROR, |
||
54 | 'error' => YiiLogger::LEVEL_ERROR, |
||
55 | 'warning' => YiiLogger::LEVEL_WARNING, |
||
56 | 'notice' => YiiLogger::LEVEL_INFO, |
||
57 | 'info' => YiiLogger::LEVEL_INFO, |
||
58 | 'debug' => YiiLogger::LEVEL_TRACE, |
||
59 | ]; |
||
60 | |||
61 | /** |
||
62 | * @inheritdoc |
||
63 | */ |
||
64 | public function init() |
||
71 | |||
72 | /** |
||
73 | * Log a message, transforming from PSR3 to the closest Yii2. |
||
74 | * |
||
75 | * @inheritdoc |
||
76 | */ |
||
77 | public function log($level, $message, array $context = []) |
||
91 | |||
92 | /** |
||
93 | * @inheritdoc |
||
94 | */ |
||
95 | public function emergency($message, array $context = []) |
||
99 | |||
100 | /** |
||
101 | * @inheritdoc |
||
102 | */ |
||
103 | public function alert($message, array $context = []) |
||
107 | |||
108 | /** |
||
109 | * @inheritdoc |
||
110 | */ |
||
111 | public function critical($message, array $context = []) |
||
115 | |||
116 | /** |
||
117 | * @inheritdoc |
||
118 | */ |
||
119 | public function error($message, array $context = []) |
||
123 | |||
124 | /** |
||
125 | * @inheritdoc |
||
126 | */ |
||
127 | public function warning($message, array $context = []) |
||
131 | |||
132 | /** |
||
133 | * @inheritdoc |
||
134 | */ |
||
135 | public function notice($message, array $context = []) |
||
139 | |||
140 | /** |
||
141 | * @inheritdoc |
||
142 | */ |
||
143 | public function info($message, array $context = []) |
||
147 | |||
148 | /** |
||
149 | * @inheritdoc |
||
150 | */ |
||
151 | public function debug($message, array $context = []) |
||
155 | |||
156 | /** |
||
157 | * Interpolates context values into the message placeholders. |
||
158 | * |
||
159 | * @param string $message |
||
160 | * @param array $context |
||
161 | * @return string |
||
162 | */ |
||
163 | private function interpolate(string $message, array $context = []) |
||
177 | } |
||
178 |