解析一个log4j日志文件[英] Parse a log4j log file

本文是小编为大家收集整理的关于解析一个log4j日志文件的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我们有几个使用log4j进行记录的应用程序.我需要让Log4J解析器正常工作,以便我们可以组合多个日志文件并对它们进行自动分析.我不想重新发明轮子,所以有人可以将我指向一个不错的现有解析器吗?如果有帮助,我确实有log4j转换模式.

如果没有,我必须自己滚动.

推荐答案

我没有意识到log4j用XML Appender发货.

解决方案是:在记录配置文件中指定XML Appender,将输出XML文件作为实体包含在形成良好的XML文件中,然后使用您喜欢的技术解析XML.

其他方法具有以下局限性:

  • apache Chainsaw - 未足够自动化
  • JDBC-高性能分布式应用程序的性能不佳

其他推荐答案

您可以使用 otroslogviewer 批处理处理.您必须:

  1. 定义您的日志格式,可以使用 log4j log4j tatter a href =" http://code.google.com/p/otroslogviewer/wiki/wiki/includededlogparsers" rel =" nofollow"> log4j xmllayout
  2. 创建实现 logdataparsedlistener .方法将在每个解析的日志事件上调用方法公共void logDataParsed(LogData数据,batchProcessingContext上下文).
  3. 创建jar
  4. 运行Otroslogviewer,并指定您的日志处理jar,logDataparSedListener实现和日志文件.

其他推荐答案

您要寻找的是锯木厂 >类似IT .

本文地址:https://www.itbaoku.cn/post/1574746.html

问题描述

We have several applications that use log4j for logging. I need to get a log4j parser working so we can combine multiple log files and run automated analysis on them. I'm not looking to reinvent the wheel, so can someone point me to a decent pre-existing parser? I do have the log4j conversion pattern if that helps.

If not, I'll have to roll our own.

推荐答案

I didn't realize that Log4J ships with an XML appender.

Solution was: specify an XML appender in the logging configuration file, include that output XML file as an entity into a well formed XML file, then parse the XML using your favorite technique.

The other methods had the following limitations:

  • Apache Chainsaw - not automated enough
  • jdbc - poor performance in a high performance distributed app

其他推荐答案

You can use OtrosLogViewer with batch processing. You have to:

  1. Define you log format, you can use Log4j pattern layout parser or Log4j XmlLayout
  2. Create java class that implements LogDataParsedListener. Method public void logDataParsed(LogData data, BatchProcessingContext context) will be called on every parsed log event.
  3. Create jar
  4. Run OtrosLogViewer with specifying your log processing jar, LogDataParsedListener implementation and log files.

其他推荐答案

What you are looking for is called SawMill, or something like it.