[英]How to log parameter from yml config file %region% via monolog
I tried to use formatter: 我尝试使用格式化程序:
services:
monolog.formatter.tits:
class: Monolog\Formatter\LineFormatter
arguments:
- "[%%datetime%%] [%extra.region%] %%channel%%.%%level_name%%: %%message%% %%context%% %%extra%%\n" "%region%"
But i failed and get this: 但是我失败了,得到了这个:
[2016-02-23 09:56:54][%region%] event.DEBUG: Notified event "kernel.terminate" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelTerminate". [] []
there is [%region%] instead my region parameter from yml config file. yml配置文件中有[%region%]而不是我的region参数。
How to make this run? 如何运行?
Finally I found answer. 最后我找到了答案。
services:
monolog.formatter.q3dm6:
class: Monolog\Formatter\LineFormatter
arguments:
- "[%%datetime%%] [region:%region%] %%channel%%.%%level_name%%: %%message%% %%context%% %%extra%%\n"
You need only one % if you want to pull it from yml config file. 如果您要从yml配置文件中提取它,则只需要一个%。 Now I getting right log:
现在我得到正确的日志:
[2016-02-23 10:50:38] [region:pl] request.CRITICAL: Uncaught PHP Exception Twig_Error_Syntax...
You need to double your '%' around the extra.region parameter to make it work: 您需要在extra.region参数周围加倍“%”以使其起作用:
services:
monolog.formatter.tits:
class: Monolog\Formatter\LineFormatter
arguments:
- "[%%datetime%%] [%%extra.region%%] %%channel%%.%%level_name%%: %%message%% %%context%% %%extra%%\n" "%%region%%"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.