Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

yaml/symfony2: Override configurations

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

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

In my test environment, I want no logger at all. So I tried

monolog: ~

with 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 a ErrorException Couldn't find constant Monolog\Logger::. If anybody could point out a way to override the monolog settings I would very much appreciate it. Thanks!

like image 922
Sgoettschkes Avatar asked Apr 27 '12 09:04

Sgoettschkes


3 Answers

It's better to define handlers as empty array:

monolog:
    handlers: []

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

monolog:
    handlers:
        test:
            type:  test
            level: debug
like image 50
lisachenko Avatar answered Nov 09 '22 05:11

lisachenko


If you're using the Symfony2 Standard Edition

Your config_dev.yml looks something like this for monolog 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 handlers main and nested where nested is only used because it's referenced by main.

config_dev.yml is imported from config_test.yml so if you want to override the configuration for your test environment you need to override the mainhandler in config_test.yml:

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

This will stop monolog from creating a log file.

like image 42
flu Avatar answered Nov 09 '22 05:11

flu


Have you tried:

monolog:
    handlers: ~

It should work (I think). Look here Without handlers, monolog is not load.

like image 1
Olivier Dolbeau Avatar answered Nov 09 '22 06:11

Olivier Dolbeau