logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Curt Arnold <carn...@apache.org>
Subject Re: Extracting information from log4j messages
Date Tue, 30 May 2006 18:07:08 GMT

On May 30, 2006, at 7:55 AM, zimske wrote:

> Hello
> I'd like to know if there's a way to extract detailed information  
> from the
> message that is generated with the defined pattern. I'm aware of
> getThreadName(), getMessage() methods and so forth. However, my layout
> formats the message with following pattern: %d{ABSOLUTE} %5p (%l) -  
> [%c] -
> %m%n. The message looks like this:
> 14:42:42,618  INFO (test.Test.main(Test.java:18)) - [test.Test] -  
> for the method call
> logger.info("BLAH BLAH");
> However, getMessage method will simply return "BLAH BLAH".
> So, basically, through patterns I can get detailed information of what
> happened, when it happened, and where it happened. Can I get these
> information (method, package, line number) through log4j API as well?

org.apache.log4j.PatternLayout produces the formatted string that you  
quoted by accessing the information from a  
org.apache.log4j.spi.LoggingEvent.  You said that you called  
getMessage() and got back "BLAH BLAH".  I'm assuming that you were  
calling getMessage() on an instance of o.a.l.spi.LoggingEvent, so you  
already have figured out how to get access to a LoggingEvent.

The elements of your specified pattern basically do the following:

%d{ABSOLUTE} - Formats the value of LoggingEvent.timestamp (also  
available using LoggingEvent.getTimestamp() in log4j 1.3).
%p - Formats the value of LoggingEvent.level (LoggingEvent.getLevel())
%l - Formats the value of LoggingEvent.getLocationInfo().
%c - Formats the value of LoggingEvent.categoryName (or  
%m - Formats the value of LoggingEvent.getMessage().

To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org

View raw message