Skip to content

Commit 4df2884

Browse files
Exceptions - Log Deprecations
1 parent f6dd565 commit 4df2884

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

app/Config/Exceptions.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,19 @@ class Exceptions extends BaseConfig
3333
*/
3434
public $ignoreCodes = [404];
3535

36+
/**
37+
* --------------------------------------------------------------------------
38+
* DO NOT FAIL ON DEPRECATIONS
39+
* --------------------------------------------------------------------------
40+
* By default deprecation errors will be thrown as exception stopping
41+
* the framework from further code execution. With this parameter set to
42+
* true the deprecations will not throw exception but instead will be written
43+
* to the log with warning level.
44+
*
45+
* @var bool
46+
*/
47+
public $failOnDeprecated = true;
48+
3649
/**
3750
* --------------------------------------------------------------------------
3851
* Error Views Path

system/Debug/Exceptions.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,20 @@ public function exceptionHandler(Throwable $exception)
153153
*/
154154
public function errorHandler(int $severity, string $message, ?string $file = null, ?int $line = null)
155155
{
156+
if ($this->config->failOnDeprecated !== true) {
157+
if ($this->config->log === true) {
158+
$exception = new ErrorException($message, 0, $severity, $file, $line);
159+
log_message('warning', "{message}\nin {exFile} on line {exLine}.\n{trace}", [
160+
'message' => $exception->getMessage(),
161+
'exFile' => clean_path($exception->getFile()), // {file} refers to THIS file
162+
'exLine' => $exception->getLine(), // {line} refers to THIS line
163+
'trace' => self::renderBacktrace($exception->getTrace()),
164+
]);
165+
}
166+
167+
return;
168+
}
169+
156170
if (! (error_reporting() & $severity)) {
157171
return;
158172
}

0 commit comments

Comments
 (0)