4

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

11
  • 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? Commented Feb 26, 2020 at 12:33
  • 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. Commented Feb 26, 2020 at 16:15
  • @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? Commented Feb 26, 2020 at 16:19
  • 1
    @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. Commented Feb 26, 2020 at 16:32
  • 1
    @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). Commented Feb 26, 2020 at 16:38

1 Answer 1

1

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"]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.