3
votes

When running Console commands in prod mode, I need to log Doctrine related debug messages. Everything works fine in dev with the following configuration, so I assume I forgot something to set when in prod?

My system:

  • PHP 7.3
  • Symfony 4.4
  • Monolog
  • Doctrine

How do I run commands:

I run commands in prod as either

php bin/console app:scrape --env=prod

or

# set APP_ENV=prod in .env.local before
php bin/console app:scrape

Both result in no logs. I am sure, I run prod, because Symfony creates var/cache/prod every time.

Monolog configuration file: config/package/prod/monolog.yaml

This file configures Monolog in prod environment.

monolog:
    handlers:
        main:
            type: fingers_crossed
            action_level: debug
            handler: nested
            excluded_http_codes: [404, 405]
        nested:
            type: stream
            path: "%kernel.logs_dir%/%kernel.environment%.log"
            level: debug
        deprecation:
            type: stream
            path: "%kernel.logs_dir%/%kernel.environment%.deprecations.log"
        deprecation_filter:
            type: filter
            handler: deprecation
            max_level: info
            channels: ["php"]
        doctrine:
            level: debug
            type: stream
            path: "%kernel.logs_dir%/doctrine/info.log"
            channels: ["doctrine"]

Output of APP_ENV=prod bin/console debug:config monolog:

https://gist.github.com/k00ni/419f62941e496a376be35a0d06e44131

1
You can check if your configuration has the desired effect by running APP_ENV=prod bin/console debug:config monolog Can you confirm that the doctrine logger is set up correctly?dbrumann
Did you try to set info or debug for action_level: error in config/package/prod/monolog.yaml. Because actually only ERROR logs will be written and if you do not have on your console command, then it will write nothing.GrenierJ
@dbrumann: I added the output of this command at the end of my question. How can i confirm, that the doctrine logger is set up correctly? If i run in dev, it logs all Doctrine output, so i assume it is set up correctly?k00ni
@GrenierJ the prod config does not override the other configuration, at least not in the sense that it will replace the other handlers. It would only override other handlers when they are defined in both places. They are both merged as can be seen in the gist.dbrumann
@dbrumann: I hope its OK, that i keeping answering here. I changed the Console command so that it doesn't return anything, which triggered a deprecation. It wrote the deprecation information in var/log/prod.deprecation.log as well as in var/log/doctrine/info.log. But not my expected Doctrine debug information (like SQLs).k00ni

1 Answers

0
votes

Maybe you could have a main handler that is grouped so that it will pass messages with both handlers (your current main and doctrine):

# config/packages/monolog.yaml
monolog:
    handlers:
        main:
            type: group
            members: ["doctrine", "default"]
        doctrine:
            level: debug
            type: stream
            path: "%kernel.logs_dir%/doctrine/info.log"
            channels: ["doctrine"]
# config/package/prod/monolog.yaml
monolog:
    handlers:
        default: # formerly main
            type: fingers_crossed
            action_level: error
            handler: nested
            excluded_http_codes: [404, 405]
        nested:
            type: stream
            path: "%kernel.logs_dir%/%kernel.environment%.log"
            level: debug
        deprecation:
            type: stream
            path: "%kernel.logs_dir%/%kernel.environment%.deprecations.log"
        deprecation_filter:
            type: filter
            handler: deprecation
            max_level: info
            channels: ["php"]