I cannot get the symfony2 configuration to correctly overwrite values from other config-files. Here is the problem:
I have a new environment "staging" where I want to use most of the stuff from config_prod.yml but have another logging level (I want it to be as it is in development, simply logging everything to a file). Here are the config stuff I use:
config_prod.yml:
imports:
- { resource: config.yml }
monolog:
handlers:
main:
type: fingers_crossed
action_level: error
handler: nested
nested:
type: stream
path: %kernel.logs_dir%/%kernel.environment%.log
level: debug
config_staging.yml:
imports:
- { resource: config_prod.yml }
monolog:
handlers:
main:
type: stream
path: %kernel.logs_dir%/%kernel.environment%.log
level: debug
nested: ~
From my point of view, the nested logger is now null and the main logs to the given file. What really happens is that he logs every message twice! The same happens when I use this for the config_staging.yml:
imports:
- { resource: config_prod.yml }
monolog:
handlers:
main:
type: stream
path: %kernel.logs_dir%/%kernel.environment%.log
level: debug
handler: ~
nested: ~
I found a workaround, setting the action_level of the main handler to debug and leaving everything else as is, but I don't like this solution. There must be a way to overwrite config stuff so I only have the main monolog handler.
Pretty much one year later I now have an understanding of what's happening and how to prevent it:
The nested
handler is befilled with the configuration from the config.yml
and when parsing the config_staging.yml
, the yaml component does not overwrite the whole hashmap and set the value to null but tries to merge both, resulting in the same array as before.
There is a type called null
which can be used ot overwrite any Logger. It does nothing and is therefor suitable for this use case:
monolog:
handlers:
main:
type: stream
path: %kernel.logs_dir%/%kernel.environment%.log
level: debug
handler: ~
nested: ~
type: null
Another solution would be to not configure any logging in the config.yml but only in the specific environment configs like config_prod.yml
and so on.
Check that you don't have any repeated keys in the _staging config file -- the second one would override the first, with the net result that the first is ignored.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With