views:

457

answers:

4

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?

+1  A: 

I'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.

Cocowalla
@coco: i saw that option, but it is expecting an XML file. whereas i am having a .log file.
Rakesh Juyal
As mentioned in my answer, Chainsaw will only read log4j formatted XML files - so I'm afraid the answer to your question is 'no', Chainsaw cannot read your logs because they are not in the expected format
Cocowalla
`I'm afraid the answer to your question is 'no'` accepted
Rakesh Juyal
A: 

Yes, Chainsaw can read regular text log files - use a LogFilePatternReceiver. See the example configuration available from the Welcome tab.

Scott
How about the text log has special/custom layout?
PerlDev
A: 

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).

Scott
How about the log record looks like:<log4j:event category="PROTO" timestamp="01-29-2010 17:13:54.65" priority="WARN" thread="Connect_693"><log4j:message><![CDATA[###Connection: Error reading object:Connection reset]]></log4j:message><log4j:NDC><![CDATA[nodaltest,10.100.129.70,XXX]]></log4j:NDC></log4j:event>
PerlDev
A: 

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.

Scott