logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ralph Goers <rgo...@apache.org>
Subject Re: Some question when migrating from log4j to log4j2
Date Tue, 28 Nov 2017 02:27:44 GMT
You can call the getSource() method of the LogEvent and it will return the StackTraceElement
of the caller.


> On Nov 27, 2017, at 7:22 PM, 代超 <daichao611@163.com> wrote:
> Hi all,
>  Nowadays I am upgrading the log component. I used to use the log4j and customize our
own appender by extending the org.apache.log4j.AppenderSkeleton in order to sending log message
to the Loghub server. Considering the higher performance, we decided to upgrade the log component
to log4j2. In oder to customize our own log4j2 appender, we extend the class org.apache.logging.log4j.core.appender.AbstractAppender,
but I found there is no way to occupy the location information without specifying a  location-related
patterns( %C or $class <https://logging.apache.org/log4j/log4j-2.2/manual/layouts.html#PatternClass>,
%F or %file <https://logging.apache.org/log4j/log4j-2.2/manual/layouts.html#PatternFile>,
%l or %location <https://logging.apache.org/log4j/log4j-2.2/manual/layouts.html#PatternLocation>,
%L or %line <https://logging.apache.org/log4j/log4j-2.2/manual/layouts.html#PatternLine>,
%M or %method <https://logging.apache.org/log4j/log4j-2.2/manual/layouts.html#PatternMethod>).
When I use log4j, it was easy to get location information by  calling 'org.apache.log4j.spi.LoggingEvent#getLocationInformation'.
So I want to ask that is there a way to get location information from log4j2's org.apache.logging.log4j.core.LogEvent?
> Best wishes!

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message