Look at the source code for Thread.getStackTrace(). When this ==
currentThread(), it calls new Exception().getStackTrace(). Less indirection
to just do it directly. ;)
On 30 March 2017 at 10:16, Ralph Goers wrote:
> I should note that in Java 9 getting the location
I should note that in Java 9 getting the location information will be much
faster.
Ralph
> On Mar 30, 2017, at 7:44 AM, Pietro Galassi wrote:
>
> Perfect.
>
> So using a method that will add location information on demand is the best
> choice. This will let remove
Perfect.
So using a method that will add location information on demand is the best
choice. This will let remove %M or the specific method finding logic
whenever it's not necessary.
Regards.
On Thu, Mar 30, 2017 at 4:36 PM, Remko Popma wrote:
>
> > On Mar 30, 2017, at
> On Mar 30, 2017, at 21:51, Pietro Galassi wrote:
>
> Thanks a lot!
>
> So:
>
> - for class name better to use %c with the LogManager.getLogger(this.class)
> instead of the calculation i do ?
Yes.
>
> - for method name avoid %M and use new
Thanks a lot!
So:
- for class name better to use %c with the LogManager.getLogger(this.class)
instead of the calculation i do ?
- for method name avoid %M and use new Throwable().getStackTrace instead
Thread.currentThread().getStackTrace() to get better performance ?
Regards
On Thu, Mar 30,
Sent from my iPhone
> On Mar 30, 2017, at 16:24, Pietro Galassi wrote:
>
> So,
>
> using such code like this:
>
> LogManager.getLogger(this.class); will let the code be fast ?
Yes.
>
>
> and it's faster than the code i published ?
Yes. The point of my answer was
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 ?
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
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 %m%n pattern is just the formatted message and a new line. The %M
pattern is for method names. And the current algorithm for finding it is
about the same: <
10 matches
Mail list logo