Skip to content

Commit fb30ae2

Browse files
authored
Merge pull request #7967 from kenjis/psr-log-v2
fix: update psr/log to v2 and fix Logger interface
2 parents 8e3dd0e + 7dd0ffd commit fb30ae2

File tree

14 files changed

+99
-194
lines changed

14 files changed

+99
-194
lines changed

admin/framework/composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"ext-json": "*",
1616
"ext-mbstring": "*",
1717
"laminas/laminas-escaper": "^2.9",
18-
"psr/log": "^1.1"
18+
"psr/log": "^2.0"
1919
},
2020
"require-dev": {
2121
"codeigniter/coding-standard": "^1.5",

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"ext-json": "*",
1616
"ext-mbstring": "*",
1717
"laminas/laminas-escaper": "^2.9",
18-
"psr/log": "^1.1"
18+
"psr/log": "^2.0"
1919
},
2020
"require-dev": {
2121
"codeigniter/coding-standard": "^1.5",

system/Common.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ function lang(string $line, array $args = [], ?string $locale = null)
794794
* - info
795795
* - debug
796796
*
797-
* @return bool
797+
* @return void
798798
*/
799799
function log_message(string $level, string $message, array $context = [])
800800
{
@@ -804,10 +804,12 @@ function log_message(string $level, string $message, array $context = [])
804804
if (ENVIRONMENT === 'testing') {
805805
$logger = new TestLogger(new Logger());
806806

807-
return $logger->log($level, $message, $context);
807+
$logger->log($level, $message, $context);
808+
809+
return;
808810
}
809811

810-
return Services::logger(true)->log($level, $message, $context); // @codeCoverageIgnore
812+
Services::logger(true)->log($level, $message, $context); // @codeCoverageIgnore
811813
}
812814
}
813815

system/ComposerScripts.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ final class ComposerScripts
5656
],
5757
'psr-log' => [
5858
'license' => __DIR__ . '/../vendor/psr/log/LICENSE',
59-
'from' => __DIR__ . '/../vendor/psr/log/Psr/Log/',
59+
'from' => __DIR__ . '/../vendor/psr/log/src/',
6060
'to' => __DIR__ . '/ThirdParty/PSR/Log/',
6161
],
6262
];
@@ -84,7 +84,6 @@ public static function postUpdate()
8484
}
8585

8686
self::copyKintInitFiles();
87-
self::recursiveDelete(self::$dependencies['psr-log']['to'] . 'Test/');
8887
}
8988

9089
/**

system/Log/Logger.php

+19-20
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use CodeIgniter\Log\Handlers\HandlerInterface;
1616
use Psr\Log\LoggerInterface;
1717
use RuntimeException;
18+
use Stringable;
1819
use Throwable;
1920

2021
/**
@@ -157,9 +158,9 @@ public function __construct($config, bool $debug = CI_DEBUG)
157158
*
158159
* @param string $message
159160
*/
160-
public function emergency($message, array $context = []): bool
161+
public function emergency(string|Stringable $message, array $context = []): void
161162
{
162-
return $this->log('emergency', $message, $context);
163+
$this->log('emergency', $message, $context);
163164
}
164165

165166
/**
@@ -170,9 +171,9 @@ public function emergency($message, array $context = []): bool
170171
*
171172
* @param string $message
172173
*/
173-
public function alert($message, array $context = []): bool
174+
public function alert(string|Stringable $message, array $context = []): void
174175
{
175-
return $this->log('alert', $message, $context);
176+
$this->log('alert', $message, $context);
176177
}
177178

178179
/**
@@ -182,9 +183,9 @@ public function alert($message, array $context = []): bool
182183
*
183184
* @param string $message
184185
*/
185-
public function critical($message, array $context = []): bool
186+
public function critical(string|Stringable $message, array $context = []): void
186187
{
187-
return $this->log('critical', $message, $context);
188+
$this->log('critical', $message, $context);
188189
}
189190

190191
/**
@@ -193,9 +194,9 @@ public function critical($message, array $context = []): bool
193194
*
194195
* @param string $message
195196
*/
196-
public function error($message, array $context = []): bool
197+
public function error(string|Stringable $message, array $context = []): void
197198
{
198-
return $this->log('error', $message, $context);
199+
$this->log('error', $message, $context);
199200
}
200201

201202
/**
@@ -206,19 +207,19 @@ public function error($message, array $context = []): bool
206207
*
207208
* @param string $message
208209
*/
209-
public function warning($message, array $context = []): bool
210+
public function warning(string|Stringable $message, array $context = []): void
210211
{
211-
return $this->log('warning', $message, $context);
212+
$this->log('warning', $message, $context);
212213
}
213214

214215
/**
215216
* Normal but significant events.
216217
*
217218
* @param string $message
218219
*/
219-
public function notice($message, array $context = []): bool
220+
public function notice(string|Stringable $message, array $context = []): void
220221
{
221-
return $this->log('notice', $message, $context);
222+
$this->log('notice', $message, $context);
222223
}
223224

224225
/**
@@ -228,19 +229,19 @@ public function notice($message, array $context = []): bool
228229
*
229230
* @param string $message
230231
*/
231-
public function info($message, array $context = []): bool
232+
public function info(string|Stringable $message, array $context = []): void
232233
{
233-
return $this->log('info', $message, $context);
234+
$this->log('info', $message, $context);
234235
}
235236

236237
/**
237238
* Detailed debug information.
238239
*
239240
* @param string $message
240241
*/
241-
public function debug($message, array $context = []): bool
242+
public function debug(string|Stringable $message, array $context = []): void
242243
{
243-
return $this->log('debug', $message, $context);
244+
$this->log('debug', $message, $context);
244245
}
245246

246247
/**
@@ -249,7 +250,7 @@ public function debug($message, array $context = []): bool
249250
* @param string $level
250251
* @param string $message
251252
*/
252-
public function log($level, $message, array $context = []): bool
253+
public function log($level, string|Stringable $message, array $context = []): void
253254
{
254255
if (is_numeric($level)) {
255256
$level = array_search((int) $level, $this->logLevels, true);
@@ -262,7 +263,7 @@ public function log($level, $message, array $context = []): bool
262263

263264
// Does the app want to log this right now?
264265
if (! in_array($level, $this->loggableLevels, true)) {
265-
return false;
266+
return;
266267
}
267268

268269
// Parse our placeholders
@@ -295,8 +296,6 @@ public function log($level, $message, array $context = []): bool
295296
break;
296297
}
297298
}
298-
299-
return true;
300299
}
301300

302301
/**

system/Test/TestLogger.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace CodeIgniter\Test;
1313

1414
use CodeIgniter\Log\Logger;
15+
use Stringable;
1516

1617
/**
1718
* @see \CodeIgniter\Test\TestLoggerTest
@@ -27,7 +28,7 @@ class TestLogger extends Logger
2728
* @param string $level
2829
* @param string $message
2930
*/
30-
public function log($level, $message, array $context = []): bool
31+
public function log($level, string|Stringable $message, array $context = []): void
3132
{
3233
// While this requires duplicate work, we want to ensure
3334
// we have the final message to test against.
@@ -52,7 +53,7 @@ public function log($level, $message, array $context = []): bool
5253
];
5354

5455
// Let the parent do it's thing.
55-
return parent::log($level, $message, $context);
56+
parent::log($level, $message, $context);
5657
}
5758

5859
/**

system/ThirdParty/PSR/Log/AbstractLogger.php

+1-114
Original file line numberDiff line numberDiff line change
@@ -11,118 +11,5 @@
1111
*/
1212
abstract class AbstractLogger implements LoggerInterface
1313
{
14-
/**
15-
* System is unusable.
16-
*
17-
* @param string $message
18-
* @param mixed[] $context
19-
*
20-
* @return void
21-
*/
22-
public function emergency($message, array $context = array())
23-
{
24-
$this->log(LogLevel::EMERGENCY, $message, $context);
25-
}
26-
27-
/**
28-
* Action must be taken immediately.
29-
*
30-
* Example: Entire website down, database unavailable, etc. This should
31-
* trigger the SMS alerts and wake you up.
32-
*
33-
* @param string $message
34-
* @param mixed[] $context
35-
*
36-
* @return void
37-
*/
38-
public function alert($message, array $context = array())
39-
{
40-
$this->log(LogLevel::ALERT, $message, $context);
41-
}
42-
43-
/**
44-
* Critical conditions.
45-
*
46-
* Example: Application component unavailable, unexpected exception.
47-
*
48-
* @param string $message
49-
* @param mixed[] $context
50-
*
51-
* @return void
52-
*/
53-
public function critical($message, array $context = array())
54-
{
55-
$this->log(LogLevel::CRITICAL, $message, $context);
56-
}
57-
58-
/**
59-
* Runtime errors that do not require immediate action but should typically
60-
* be logged and monitored.
61-
*
62-
* @param string $message
63-
* @param mixed[] $context
64-
*
65-
* @return void
66-
*/
67-
public function error($message, array $context = array())
68-
{
69-
$this->log(LogLevel::ERROR, $message, $context);
70-
}
71-
72-
/**
73-
* Exceptional occurrences that are not errors.
74-
*
75-
* Example: Use of deprecated APIs, poor use of an API, undesirable things
76-
* that are not necessarily wrong.
77-
*
78-
* @param string $message
79-
* @param mixed[] $context
80-
*
81-
* @return void
82-
*/
83-
public function warning($message, array $context = array())
84-
{
85-
$this->log(LogLevel::WARNING, $message, $context);
86-
}
87-
88-
/**
89-
* Normal but significant events.
90-
*
91-
* @param string $message
92-
* @param mixed[] $context
93-
*
94-
* @return void
95-
*/
96-
public function notice($message, array $context = array())
97-
{
98-
$this->log(LogLevel::NOTICE, $message, $context);
99-
}
100-
101-
/**
102-
* Interesting events.
103-
*
104-
* Example: User logs in, SQL logs.
105-
*
106-
* @param string $message
107-
* @param mixed[] $context
108-
*
109-
* @return void
110-
*/
111-
public function info($message, array $context = array())
112-
{
113-
$this->log(LogLevel::INFO, $message, $context);
114-
}
115-
116-
/**
117-
* Detailed debug information.
118-
*
119-
* @param string $message
120-
* @param mixed[] $context
121-
*
122-
* @return void
123-
*/
124-
public function debug($message, array $context = array())
125-
{
126-
$this->log(LogLevel::DEBUG, $message, $context);
127-
}
14+
use LoggerTrait;
12815
}

system/ThirdParty/PSR/Log/LoggerAwareTrait.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ trait LoggerAwareTrait
1212
*
1313
* @var LoggerInterface|null
1414
*/
15-
protected $logger;
15+
protected ?LoggerInterface $logger = null;
1616

1717
/**
1818
* Sets a logger.

0 commit comments

Comments
 (0)