So,

using such code like this:

LogManager.getLogger(this.class); will let the code be fast ?


and it's faster than the code i published ?


Also why  new Throwable().getStackTrace is faster than
Thread.currentThread().getStackTrace(). ?
Does the new in Throwable can give performance issue ?


Regards.


On Wed, Mar 29, 2017 at 5:49 PM, Remko Popma <remko.po...@gmail.com> wrote:

> Pietro,
>
> The performance impact of logging location information is massive.
> See
> https://logging.apache.org/log4j/2.x/performance.html#
> asyncLoggingWithLocation
>
> You can increase logging speed by ~80x by not logging location information.
>
> If you follow the conventions that each class has its own logger (and the
> logger name is the class that it is for), then %c or %logger in the pattern
> layout will tell you the name of the class. Then all that remains is make
> your log messages informative enough that you don't need line numbers to
> disambiguate them.
>
> Remko
>
>
> On Thu, Mar 30, 2017 at 12:42 AM, Ralph Goers <ralph.go...@dslextreme.com>
> wrote:
>
> > 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