我正试图在Symfony WebApp中使用自定义格式化程序来创建Monlog日志条目:
//config.yml
services:
monolog.formatter.extended:
class: Monolog\Formatter\LineFormatter
arguments:
format: "[%%datetime%%] %%channel%%.%%level_name%% ...\n\n"
allowInlineLineBreaks: true
ignoreEmptyContextAndExtra: true
calls:
- [includeStacktraces]
所有使用该格式器创建的日志条目都以
[1]...
开头,而不是插入正确的时间戳[2015-12-16 10:40:23]...
。当我删除两个额外的参数
allowInlineLineBreaks
和ignoreEmptyContextAndExtra
时,此问题不会出现。arguments:
format: "[%%datetime%%] %%channel%%.%%level_name%% ...\n\n"
然而,当我不通过名称传递参数,而只是将它们作为完整列表传递时,一切正常运行。
LineFormatter
构造函数如下所示:public function __construct($format = null, $dateFormat = null, $allowInlineLineBreaks = false, $ignoreEmptyContextAndExtra = false) { ...}
因此,将参数作为列表添加可以正常工作:
arguments:
- "[%%datetime%%] %%channel%%.%%level_name%% ...\n\n"
- null
- true
- true
传递参数时使用名称有什么问题吗?我在几个示例中看到了这种用法,但显然我在使用方式上存在问题?