You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by zimske <zi...@gmail.com> on 2006/05/30 14:55:14 UTC

Extracting information from log4j messages

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] - BLAH BLAH

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?


--
View this message in context: http://www.nabble.com/Extracting+information+from+log4j+messages-t1704397.html#a4626356
Sent from the Log4j - Users forum at Nabble.com.


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


Re: Extracting information from log4j messages

Posted by zimske <zi...@gmail.com>.
-----------
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  
LoggingEvent.getLoggerName()).
%m - Formats the value of LoggingEvent.getMessage(). 
---------------

Thanks for replies, guys, i've figured it out. The key is to call methods on
this one:

LoggingEvent.getLocationInformation().

There are methods that when called on the object above, return the line
number (logEvent.getLocationInformation().getLineNumber()) method name
(logEvent.getLocationInformation().getMethodName()), full information
(logEvent.getLocationInformation().fullInfo) and so forth. 

--
View this message in context: http://www.nabble.com/Extracting+information+from+log4j+messages-t1704397.html#a4639874
Sent from the Log4j - Users forum at Nabble.com.


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


Re: Extracting information from log4j messages

Posted by Curt Arnold <ca...@apache.org>.
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] -  
> BLAH BLAH
>
> 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  
LoggingEvent.getLoggerName()).
%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


Re: Extracting information from log4j messages

Posted by James Stauffer <st...@gmail.com>.
Look at the code to see how it gets that info.

On 5/30/06, zimske <zi...@gmail.com> 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] - BLAH BLAH
>
> 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?
>
>
> --
> View this message in context: http://www.nabble.com/Extracting+information+from+log4j+messages-t1704397.html#a4626356
> Sent from the Log4j - Users forum at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>


-- 
James Stauffer
Are you good? Take the test at http://www.livingwaters.com/good/

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