Skip to content

Commit ec2af94

Browse files
committed
fix: incorrect Logger interface
1 parent 94a25b2 commit ec2af94

3 files changed

Lines changed: 27 additions & 25 deletions

File tree

‎system/Common.php‎

Lines changed: 5 additions & 3 deletions
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/Log/Logger.php‎

Lines changed: 19 additions & 20 deletions
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‎

Lines changed: 3 additions & 2 deletions
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
/**

0 commit comments

Comments
 (0)