I am having several log files [ generated via log4j ]. I got to know that we can use Chainsaw to read those logs [ though we can reads those logs in notepad as well ].
But i am unable to figure out how to open a stored log file to see its content. So the simple question is, Is it possible to read the log file using Chainsaw?
views:
457answers:
4I'm using Chainsaw v2 Log Viewer on Windows.
In the File menu there is an option 'Load Log4j file', which will allow you to open a Log4j XML log file.
Of course, the file you are trying to open must confirm to the log4j XML schema.
Yes, Chainsaw can read regular text log files - use a LogFilePatternReceiver. See the example configuration available from the Welcome tab.
Yes - as long as each log entry ends with the 'message' and is newline delimited, you should be able to parse the log file using LogFilePatternReceiver.
Example log line:
20100128 11:35:34.546 [main] INFO - package1.package2.SomeLoggerName - Message here line1 message here line2
These two lines, representing one log entry, can be parsed with this logFormat:
TIMESTAMP [THREAD] LEVEL - LOGGER - MESSAGE
See the LogFilePatternReceiver JavaDoc for more information (available from Chainsaw's help menu) and the example receiver configuration (available from the Welcome tab, the 'view example receiver configuration' button).
Your log file contains 'priority' and 'category' attributes instead of 'level', 'logger', which are supported by default in Chainsaw.
Can you change your layout to generate level & category attributes? If so, Chainsaw should be able to process your log file.
If you need to use category & priority attribute names, I'd suggest pulling down log4j's XmlDecoder source and modifying it to accept priority & category attribute names. You can then configure Chainsaw to use a LogFileXMLReceiver and specify your own Decoder implementation.
Chainsaw's Welcome tab provides an example receiver configuration.
Here's the source for XMLDecoder: http://svn.apache.org/viewvc/logging/log4j/companions/receivers/trunk/src/main/java/org/apache/log4j/xml/XMLDecoder.java?view=log
The JavaDoc for LogFileXMLReceiver should be available from Chainsaw's help menu.