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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]