根据https://cloud.google.com/logging/docs/agent/installation的指示,我在Google Cloud上运行了一个虚拟机,并通过google-fluentd安装了日志。我为应用程序设置了一个自定义配置,将日志输出到/var/log/myapp.log。
我创建了一个名为tomcat.conf
的配置(作为root,几乎是/etc/google-fluentd/config.d/myapp.conf
的副本),其中包含以下内容:
<source>
@type tail
format multiline
# Match the date at the beginning of each entry
format_firstline /^(\d+\/\d+\/\d+\s\d+:\d+:\d+\s)/
format1 /(?<message>.*)/
path /var/log/myapp.log
pos_file /var/lib/google-fluentd/pos/myapp-multiline.pos
read_from_head true
tag myapp
</source>
条目显示在Stackdriver中,但只有在下一个条目放入.log文件并显示为错误的时间(即第1行获得第2行的时间戳)后才进入Stackdriver。
.conf文件中是否存在可能导致此问题的内容?
答案 0 :(得分:2)
来自in_tail
插件的documentation:
使用
format_firstline
,in_tail延迟记录发出直到下一个format_firstline
匹配,因为如果没有format_firstline
触发器,in_tail无法判断多行日志是否已结束。如果您的正则表达式正确表示日志模式,就像上面的Rails示例一样,您可以删除format_firstline
以立即发出记录。