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 Ralph Goers <rg...@apache.org> on 2017/11/28 02:27:44 UTC

Re: Some question when migrating from log4j to log4j2

You can call the getSource() method of the LogEvent and it will return the StackTraceElement of the caller.

Ralph

> On Nov 27, 2017, at 7:22 PM, 代超 <da...@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!
> 
> 
>