I’ve tried everything and i cant save an ‘info’ log into prod.log or anything else than dev.log. Errors are saving correctly in prod.log.
Is something wrong with this code? Im using newest version of symfony and monolog.
monolog.yaml:
when@prod:
monolog:
handlers:
main:
type: fingers_crossed
action_level: warning
handler: nested
excluded_http_codes: [404, 405]
buffer_size: 50 # How many messages should be saved? Prevent memory leaks
nested:
type: stream
path: '%kernel.logs_dir%/%kernel.environment%.log'
level: debug
formatter: monolog.formatter.json
console:
type: console
process_psr_3_messages: false
channels: ["!event", "!doctrine"]
and here’s my controlller:
#[Route('/test', name: 'app_test')]
public function index(LoggerInterface $logger): Response
{
$logger->info('test');
return $this->render('test/index.html.twig', [
]);
}
i’ve tried to add
deprecation:
type: stream
level: info
channels: [php]
path: '%kernel.logs_dir%/deprecated.log'
but it does not help
2
Answers
Thank you - @Waaghals for hint. I've made it :)
On top of monolog.yaml file is a tiny helper comment:
After implemented it:
It logs everything equal or above level 'info' in production to 'info.log'.
This main handler of type fingers_crossed is likely filtering the messages.
The fingers cross will buffer logs from the handler that it wraps.
And only when its trigger level is reached, it will flush its buffer.
See
handler: nested
, which means it is wrapping the nested handler.And the trigger level of the main handler is set to
action_level: warning
.So you nested handler is logging everything higher then log level debug.
But the main handler is wrapping it, and it will only flush the buffer once there is a log message of warning and higher.
In your controller, there is only logs of level info. Meaning the trigger level was not reached, and the buffer was not flushed.
Either lower the action_level on the main handler, or trigger logging by creating a log of at least level warning.