I'd like to upgrade from Symfony 4.4. to 5.0. So I have to check for deprecations in the code. The symfony migration guide says I have to use the web dev toolbar, but in my API-app there is no frontend for the tool-bar.
How can I configure symfony/monolog to log deprecation warnings to the log file?
Update I have created a minimal example:
composer create-project symfony/website-skeleton:4.3.99
TestController.php
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* Class ApiController
* @package App\Controller
* @Route("", defaults={"_format"="json"})
*
*/
class TestController extends AbstractController
{
/**
* @Route("/test", name="test")
* @param Request $request
* @return Response
*/
public function test(Request $request): Response
{
@trigger_error(sprintf('DEMO DEPRECATION', __METHOD__), E_USER_DEPRECATED);
return $this->json([
'test' => '1'
]);
}
}
monolog.yml
monolog:
handlers:
main:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
channels: ["!event"]
# uncomment to get logging in your browser
# you may have to allow bigger header sizes in your Web server configuration
#firephp:
# type: firephp
# level: info
#chromephp:
# type: chromephp
# level: info
console:
type: console
process_psr_3_messages: false
channels: ["!event", "!doctrine", "!console"]
deprecation_stream:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.deprecations.log"
deprecation_filter:
type: filter
handler: deprecation_stream
max_level: info
channels: ["php"]
run server
bin/console server:run
But the dev.deprecations.log is still empty.
There was a bug in Symfony 4.4 which is now fixed. More details here.