Skip to content

Instantly share code, notes, and snippets.

@wouterj
Created November 14, 2021 14:42
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wouterj/130433d044089d1dbf73758ab989c771 to your computer and use it in GitHub Desktop.
Save wouterj/130433d044089d1dbf73758ab989c771 to your computer and use it in GitHub Desktop.
{
"require": {
"symfony/error-handler": "^5.3"
}
}
<?php
require_once 'vendor/autoload.php';
use Psr\Log\AbstractLogger;
use Symfony\Component\ErrorHandler\ErrorHandler;
ErrorHandler::register()
->setDefaultLogger(new class extends AbstractLogger {
public function log($level, string|\Stringable $message, array $context = []): void
{
$formattedLogLine = sprintf(
'[%s] %s: %s%s'.PHP_EOL,
date('Y-m-dTH:i:s.uP'),
$level,
(string) $message,
($context['exception'] ?? false) instanceof \Throwable
? sprintf(' in %s:%s', $context['exception']->getFile(), $context['exception']->getLine())
: ''
);
file_put_contents(__DIR__.'/deprecations.log', $formattedLogLine, \FILE_APPEND);
}
}, \E_DEPRECATED | \E_USER_DEPRECATED)
;
// "null" argument deprecated as of PHP 8.1
var_dump(str_contains('foo', null));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment