How to check if a log entry was written with a given ConversionPattern?

自闭症网瘾萝莉.ら 提交于 2019-12-11 07:04:24

问题


I have many log files and I have a few log4j configurations (different ConversionPattern formats for file appenders).

I would like to write a script/test which is able to group log files by a ConversionPattern which was used to write a file. The bit I'm missing is how to implement something like:

boolean logToPatternMatcher.matches(String conversionPattern, String logFileEntry)

Is it possible with Log4j API?

The above method should return true for a given:

String conversionPattern = "%d{ISO8601} %-5p [%-16.16t][%c] %m%n"

String logFileEntry = "2015-02-12 00:02:38,023 WARN [pool-58-thread-1][some.package.name.ConvertingPublisher] Document [type: app.MessageProcessed, id: 1063_1_20150128072222800] DUPLICATED."


回答1:


GROK is perfect for your use case. I have been using it with logstash recently but there is a java-grok project on github you could try. I found this link from another stackoverflow answer.

GROK is essentially a regexp engine. It has a bunch of pre-defined regexp's that will match most common logging entries like timestamps, logging level etc. If that doesn't work out for you have you thought about using straight regexp?



来源:https://stackoverflow.com/questions/28482881/how-to-check-if-a-log-entry-was-written-with-a-given-conversionpattern

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