Yaml / symfony2: override configurations

I want to override some configurations from config_dev.yml in my config_test.yml. So imagine the following part in the config_dev.yml file:

monolog: handlers: main: type: stream path: %kernel.logs_dir%/%kernel.environment%.log level: debug firephp: type: firephp level: info 

In my test environment, I don’t want to register at all. So I tried

 monolog: ~ 

no effect. I also tried:

 monolog: handlers: main: ~ firephp: ~ 

again without any effect. Then i tested

 monolog: handlers: main: type: ~ path: ~ level: ~ firephp: type: ~ level: ~ 

and I get ErrorException Couldn't find constant Monolog\Logger:: . If anyone could specify a way to override monologue settings, I would really appreciate it. Thanks!

+6
source share
3 answers

It is better to define handlers as an empty array:

 monolog: handlers: [] 

UPD1: There are special types of loggers: test and null, you can use them:

 monolog: handlers: test: type: test level: debug 
+8
source

If you are using Symfony2 Standard Edition

Your config_dev.yml looks something like this for a monologue out of the box:

 # config_dev.yml monolog: handlers: main: type: fingers_crossed action_level: error handler: nested nested: type: stream path: %kernel.logs_dir%/%kernel.environment%.log level: debug 

As you can see, this defines the main and nested handlers, where nested used only because main refers to it.

config_dev.yml imported from config_test.yml , so if you want to override the configuration for the test environment, you need to override the main handler in config_test.yml :

 # config_text.yml monolog: handlers: main: type: test 

This will stop the monologue from creating the log file.

+3
source

You tried:

 monolog: handlers: ~ 

It should work (I think). Look here. Without handlers, a monologue is not a burden.

+1
source

Source: https://habr.com/ru/post/914313/


All Articles