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, 代超 <> 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 
> <>,
>  %F or %file 
> <>, 
> %l or %location 
> <>,
>  %L or %line 
> <>, 
> %M or %method 
> <>).
>  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!

Reply via email to