regex - 图案不匹配
问题描述
我有简单的流利的conf:
<source>
@type tail
@id in_tail_springboot_container_logs
#path /var/log/containers/*.log
path /var/log/logtest.txt
#path /var/log/containers/springbootrabbitmqlistener-*.log
pos_file /var/log/fluentd-springboot-containers.log.pos
@log_level debug
multiline_flush_interval 5s
format multiline
format1 (?<timestamp>\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}) (?<level>INFO|ERROR|WARN|TRACE|DEBUG|FATAL)\s+\[(?<app>[^\,]+),(?<zipkintraceid>[^\,]*),(?<zipkinspanid>[^\,]*),(?<zipkinsent>[^\]]*)] (?<someid>[0-9]+) --- \[(?<thread>[^\]]+)] (?<classname>[^\ ]+)\s+\: (?<text>.*)
format_firstline ?<timestamp>\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}
tag springboot.*
read_from_head true
<parse>
@type json
time_format %Y-%m-%dT%H:%M:%S.%NZ
</parse>
</source>
我用输入线测试它:
2018-11-09 08:49:36.111 INFO [SpringBootMicroservice,,,] 5820 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'environmentManager' has been autodetected for JMX exposure
我已经用https://regex101.com/对其进行了测试。
一切正常。
问题是流利的不喜欢它:
2018-11-09 08:48:18 +0000 [warn]: #0 [in_tail_springboot_container_logs] pattern not match: "2018-11-09 08:49:36.111 INFO [SpringBootMicroservice,id1,id2,true] 5820 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'environmentManager' has been autodetected for JMX exposure"
你能告诉我我的conf有什么问题吗?
解决方案
看起来问题出在这一行:
format_firstline ?<timestamp>\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}
问题是时间戳命名组的格式不正确 - 它需要整个组周围的括号,如下所示:
↓ ↓
format_firstline (?<timestamp>\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3})
↑
.
并且为了良好的实践,(正如正则表达式老手 Wiktor 所提到的),当您的 ' 应该是文字点而不是通配符时,您应该转义它们。
推荐阅读
- python - Numpy:从另一个矩阵创建块矩阵的函数,每个块应该包含来自另一个矩阵的相同索引的值
- git - R Studio 和 Git 不会同步
- ruby - 使用 rails 获取桌面中文件的路径
- javascript - 如何在 blob/buffer 的 MIME 类型之间进行转换?
- c# - 难以理解沿局部和全球空间统一的运动
- c++ - 有没有什么东西限制了未来的 C++ 标准引入多个返回值?
- openssl - 使用 OpenSSL CLI 从 x509 证书获取链或 CA 颁发者
- bash - 使用包含单引号的 grep 命令创建别名
- php - Php 不会捕获内容的结果,而只会捕获标题
- python - Python 在 MacOS 10.15 Beta (19A582a) 上使用“/usr/lib/libcrypto.dylib”崩溃