0

I am writing a Perl program to parse the output of a log file in Tomcat. This log file is created by our webapp using Log4J. I could parse the log directly, but I thought it would be easier, faster, and cleaner if there was a good module that will correctly parse the various fields in the log file.

I know modules that will allow me to parse Apache logs, but I was wondering if there's a similar module for Log4J.

David W.
  • 105,218
  • 39
  • 216
  • 337
  • How did `Log::Log4perl` work for you? – admdrew Jan 14 '14 at 21:37
  • @admdrew OP wants to parse an existing log, not write to a new one. – ThisSuitIsBlackNot Jan 14 '14 at 21:46
  • If you can change the Log4j settings, [this question](http://stackoverflow.com/questions/2327073/parse-a-log4j-log-file) might be useful. The accepted answer is to configure an XML appender and parse that. – ThisSuitIsBlackNot Jan 14 '14 at 21:58
  • Can't change the Log4J settings. The logs are used in other programs, so I can't touch the format. I guess I can try parsing the log4j.properties myself. – David W. Jan 14 '14 at 22:32
  • The XML appender would be *in addition* to the existing appenders, so the other programs could continue on their merry way. If you don't have access to the configuration, of course, that's a different issue. – ThisSuitIsBlackNot Jan 14 '14 at 23:13
  • @ThisSuitIsBlackNot I'll have to talk to the developers about this. It might be something we can do for the next release. XML parsing would make it easier. However, for now, I'll munge the parsing myself. Maybe write a module. The format of the Log4J is specified in `log4j.properties`, and I can use that to match the line - maybe using unpack/pack. – David W. Jan 15 '14 at 14:56
  • I just checked the Log4J homepage and looked at the [Appender documentation](http://logging.apache.org/log4j/2.x/manual/appenders.html). I don't see anything about XMLAppenders. Can someone point me to the documentation? – David W. Jan 15 '14 at 16:46
  • Okay, it's XMLLayout and not XMLAppender. It doesn't look too promising. It appears that all of the data is embedded in a single `<![CDATA[...]]>` data entity. – David W. Jan 15 '14 at 17:36

0 Answers0