[英]yaml/symfony2: Override configurations
I wanto to override some configurations from config_dev.yml in my config_test.yml. 我想在config_test.yml中覆盖config_dev.yml中的一些配置。 So, imagine the following part in the config_dev.yml: 所以,想象一下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::
. 我得到一个ErrorException Couldn't find constant Monolog\\Logger::
Monolog Couldn't find constant Monolog\\Logger::
。 If anybody could point out a way to override the monolog settings I would very much appreciate it. 如果有人能指出一种方法来覆盖monolog设置,我将非常感激。 Thanks! 谢谢!
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: UPD1:有特殊类型的记录器:test和null,你可以使用它们:
monolog:
handlers:
test:
type: test
level: debug
Your config_dev.yml
looks something like this for monolog out of the box: 您的config_dev.yml
看起来像是开箱即用的monolog:
# 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
. 正如你所看到的这个定义的处理程序main
和nested
其中nested
仅使用,因为它是由引用的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 main
handler in config_test.yml
: config_dev.yml
从进口config_test.yml
所以如果你想覆盖配置测试环境,你需要重写main
处理器在config_test.yml
:
# config_text.yml
monolog:
handlers:
main:
type: test
This will stop monolog from creating a log file. 这将阻止monolog创建日志文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.