skip to Main Content

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


  1. Chosen as BEST ANSWER

    Thank you - @Waaghals for hint. I've made it :)

    On top of monolog.yaml file is a tiny helper comment:

    monolog:
        channels:
            - deprecation # Deprecations are logged in the dedicated "deprecation" channel when it exists
    

    After implemented it:

                deprecation:
                    type: stream
                    level: info
                    channels: ["!event"]
                    path: '%kernel.logs_dir%/info.log'
    

    It logs everything equal or above level 'info' in production to 'info.log'.


  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search