What Java version are you using?  Why do you think your code is going to 
perform better than what Log4j is doing?

The fastest way to get the caller information is to use Java 9’s 
StackWalker.getCallerClass() method which only takes a couple of milliseconds. 
But doing that might actually make the application perform worse as you would 
potentially be capturing that information even for events that are not going to 
be logged.

Ralph

> On Mar 29, 2017, at 3:42 AM, Pietro Galassi <pietro.gala...@gmail.com> wrote:
> 
> Hi,
> 
> sorry for boothering you all.  I'm in the need to have a logging
> optimization and i whould like to ask you all about the use of %m%n.
> 
> Due to the fact i need optimization should i use :
> 
> %m%n
> 
> or should implement my own Class/Method name finder with:
> 
> 
> private static String getLoggingMethod() {
> StackTraceElement stackTraceElements[] = Thread.currentThread().
> getStackTrace();
> StackTraceElement caller = stackTraceElements[3];
> return caller.getMethodName();
> }
> 
> and
> 
> 
> private String getLoggingMethodClassNameIfDebug(int deep) {
> if (logger.isDebugEnabled()) {
> StackTraceElement stackTraceElements[] = Thread.currentThread().
> getStackTrace();
> StackTraceElement caller = stackTraceElements[deep];
> return buildMehodNameClassNameByStackTrace(caller);
> } else {
> return EMPTY;
> }
> }
> 
> 
> ?
> 
> Thanks a lot in advice.
> 
> Best regards,
> Pietro



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

Reply via email to