Need help in writing the grok pattern

只愿长相守 提交于 2019-12-12 04:04:06

问题


Can anybody help me writing the grok pattern for the following log line

07-Aug-2017|00:35:08,748 DEBUG [hostname] [Some WebApp Name] [6.9] [127.0.0.1] [1277]

I am not able to find a way to accomodate '[' & ']' in the grok patterns.

Any help will be appreciated.


回答1:


This should match your pattern:

%{MONTHDAY}-%{MONTH}-%{YEAR}\|%{TIME} %{LOGLEVEL} \[%{WORD} ] \[%{DATA}] \[%{NUMBER}] \[%{IP}] \[%{NUMBER}]

As you can see squared bracket are escaped with backslashes like this: \[ and \]

You might want to add semantic to it like so:

%{MONTHDAY:day}-%{MONTH:month}-%{YEAR:year}\|%{TIME:time} %{LOGLEVEL:loglevel} \[%{WORD:hostname} ] \[%{DATA:webapp}] \[%{NUMBER:somenumber}] \[%{IP:userip}] \[%{NUMBER:anothernumber}]

You can also test your grok patterns online e.g. here.



来源:https://stackoverflow.com/questions/45559913/need-help-in-writing-the-grok-pattern

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!