Parsing the log4j log file

We have several applications that use log4j for logging. I need to get the log4j handler to work so that we can combine several log files and do an automatic analysis on them. I'm not going to reinvent the wheel, so can someone point me to a decent parser that already exists? I have a log4j conversion template if that helps.

If not, I have to turn off.

+7
file logging parsing log4j
source share
5 answers

I did not understand that log4J comes with an XML application.

Soltuion was: specify the xml appender in the logging configuration file, include this output xml file as an object in a well-formed XML file, and then parse the xml using your favorite method.

Other methods had the following limitations:

  • chainsaw - not automated enough
  • jdbc - poor performance in a high-performance distributed application
+8
source share

You can use OtrosLogViewer with batch processing , you must:

  • Define the log format, you can use Log4j pattern layout parser or Log4j XmlLayout
  • Create a java class that implements LogDataParsedListener . The public void logDataParsed method (LogData data, BatchProcessingContext context) will be called in each log event being analyzed.
  • Create jar
  • Launch OtrosLogViewer with your log processing ATM, LogDataParsedListener implementation, and log files.
+3
source share

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

+2
source share

Log4j log files are not suitable for parsing; they are too complex and unstructured. There are third-party tools that can do this, I think (like Sawmill).

If you need to perform automatic selective analysis of logs, you should consider logging in a database and analyzing this. JDBC comes with JdbcAppender , which adds all the messages to the database of your choice, but has performance implications, and this is a bit flaky. There are other similar alternatives in interweb (like this one ).

+1
source share

You can use Log4j Chainsaw V2 to process various log files and collect them into one table, as well as output these events as xml or use the built-in filtering based on the expressions, search and colorize Chainsaw to cut and cube logs.

Steps: - Start the chainsaw V2 - Create a chainsaw configuration file by copying the example configuration file available on the Greetings tab - define one LogFilePatternReceiver 'plugin' entry for each log file that you want to process - Run the chainsaw with this configuration - Each log file will be appear as a separate tab in the user interface. - Pause the "chainsaw" tab and clear events from this tab - Create a new tab that combines events from different tabs by going to the menu item "view, crate custom expression logpanel" and enter "level> = DEBUG" in the field. It will create a new tab containing events from all tabs with> = debug level (which is why you have cleared the chainsaw log tab).

You can get an overview of the syntax of an expression used to filter, colorize, and search from a tutorial (available in the Help menu).

If you do not want to use Chainsaw, you can do something similar - run a simple application that does not register, but loads the log4j.xml configuration file using the "plugin" entries that you defined for the Chainsaw configuration, but also define FileAppender with xmllayout - All events received by the "receivers" will be sent to one application.

0
source share

All Articles