Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 14 |
|
0.00% |
0 / 12 |
CRAP | |
0.00% |
0 / 1 |
LoggerProxy | |
0.00% |
0 / 14 |
|
0.00% |
0 / 12 |
182 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
emerg | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
alert | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
crit | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
err | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
warn | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
notice | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
info | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
debug | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
logException | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
__call | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getLogger | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | /** |
4 | * VuFind Logger Proxy |
5 | * |
6 | * PHP version 8 |
7 | * |
8 | * Copyright (C) The National Library of Finland 2024. |
9 | * |
10 | * This program is free software; you can redistribute it and/or modify |
11 | * it under the terms of the GNU General Public License version 2, |
12 | * as published by the Free Software Foundation. |
13 | * |
14 | * This program is distributed in the hope that it will be useful, |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | * GNU General Public License for more details. |
18 | * |
19 | * You should have received a copy of the GNU General Public License |
20 | * along with this program; if not, write to the Free Software |
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 | * |
23 | * @category VuFind |
24 | * @package Error_Logging |
25 | * @author Ere Maijala <ere.maijala@helsinki.fi> |
26 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
27 | * @link https://vufind.org Main Site |
28 | */ |
29 | |
30 | namespace VuFind\Log; |
31 | |
32 | use function call_user_func_array; |
33 | use function func_get_args; |
34 | |
35 | /** |
36 | * This class provides a lazy-initializing proxy for the actual logger class |
37 | * |
38 | * @category VuFind |
39 | * @package Error_Logging |
40 | * @author Ere Maijala <ere.maijala@helsinki.fi> |
41 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
42 | * @link https://vufind.org Main Site |
43 | */ |
44 | class LoggerProxy implements \Laminas\Log\LoggerInterface, ExtendedLoggerInterface |
45 | { |
46 | /** |
47 | * Callback for creating the actual class |
48 | * |
49 | * @var callable |
50 | */ |
51 | protected $callback; |
52 | |
53 | /** |
54 | * Logger implementation |
55 | * |
56 | * @var Logger |
57 | */ |
58 | protected $logger = null; |
59 | |
60 | /** |
61 | * Constructor |
62 | * |
63 | * @param callable $callback Callback for creating the actual class |
64 | */ |
65 | public function __construct(callable $callback) |
66 | { |
67 | $this->callback = $callback; |
68 | } |
69 | |
70 | /** |
71 | * Log an emergency |
72 | * |
73 | * @param string $message Message |
74 | * @param array|Traversable $extra Extra params |
75 | * |
76 | * @return LoggerInterface |
77 | */ |
78 | public function emerg($message, $extra = []) |
79 | { |
80 | return $this->__call(__FUNCTION__, func_get_args()); |
81 | } |
82 | |
83 | /** |
84 | * Log an alert |
85 | * |
86 | * @param string $message Message |
87 | * @param array|Traversable $extra Extra params |
88 | * |
89 | * @return LoggerInterface |
90 | */ |
91 | public function alert($message, $extra = []) |
92 | { |
93 | return $this->__call(__FUNCTION__, func_get_args()); |
94 | } |
95 | |
96 | /** |
97 | * Log a critical error |
98 | * |
99 | * @param string $message Message |
100 | * @param array|Traversable $extra Extra params |
101 | * |
102 | * @return LoggerInterface |
103 | */ |
104 | public function crit($message, $extra = []) |
105 | { |
106 | return $this->__call(__FUNCTION__, func_get_args()); |
107 | } |
108 | |
109 | /** |
110 | * Log an error |
111 | * |
112 | * @param string $message Message |
113 | * @param array|Traversable $extra Extra params |
114 | * |
115 | * @return LoggerInterface |
116 | */ |
117 | public function err($message, $extra = []) |
118 | { |
119 | return $this->__call(__FUNCTION__, func_get_args()); |
120 | } |
121 | |
122 | /** |
123 | * Log a warning |
124 | * |
125 | * @param string $message Message |
126 | * @param array|Traversable $extra Extra params |
127 | * |
128 | * @return LoggerInterface |
129 | */ |
130 | public function warn($message, $extra = []) |
131 | { |
132 | return $this->__call(__FUNCTION__, func_get_args()); |
133 | } |
134 | |
135 | /** |
136 | * Log a notice |
137 | * |
138 | * @param string $message Message |
139 | * @param array|Traversable $extra Extra params |
140 | * |
141 | * @return LoggerInterface |
142 | */ |
143 | public function notice($message, $extra = []) |
144 | { |
145 | return $this->__call(__FUNCTION__, func_get_args()); |
146 | } |
147 | |
148 | /** |
149 | * Log an info message |
150 | * |
151 | * @param string $message Message |
152 | * @param array|Traversable $extra Extra params |
153 | * |
154 | * @return LoggerInterface |
155 | */ |
156 | public function info($message, $extra = []) |
157 | { |
158 | return $this->__call(__FUNCTION__, func_get_args()); |
159 | } |
160 | |
161 | /** |
162 | * Log a debug message |
163 | * |
164 | * @param string $message Message |
165 | * @param array|Traversable $extra Extra params |
166 | * |
167 | * @return LoggerInterface |
168 | */ |
169 | public function debug($message, $extra = []) |
170 | { |
171 | return $this->__call(__FUNCTION__, func_get_args()); |
172 | } |
173 | |
174 | /** |
175 | * Log an exception triggered by the framework for administrative purposes. |
176 | * |
177 | * @param \Exception $error Exception to log |
178 | * @param \Laminas\Stdlib\Parameters $server Server metadata |
179 | * |
180 | * @return void |
181 | */ |
182 | public function logException($error, $server) |
183 | { |
184 | return $this->__call(__FUNCTION__, func_get_args()); |
185 | } |
186 | |
187 | /** |
188 | * Proxy any other Logger method |
189 | * |
190 | * @param string $methodName The name of the called method |
191 | * @param array $params Array of passed parameters |
192 | * |
193 | * @return mixed Varies by method |
194 | */ |
195 | public function __call($methodName, $params) |
196 | { |
197 | return call_user_func_array([$this->getLogger(), $methodName], $params); |
198 | } |
199 | |
200 | /** |
201 | * Get logger |
202 | * |
203 | * @return Logger |
204 | */ |
205 | protected function getLogger(): Logger |
206 | { |
207 | if (null === $this->logger) { |
208 | ($this->callback)($this->logger, $this); |
209 | } |
210 | return $this->logger; |
211 | } |
212 | } |