logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ceki Gülcü <c...@qos.ch>
Subject Re: Measuring logging performance impact (including string concatenation)
Date Tue, 23 Feb 2010 19:58:30 GMT
NDC can be simulated with MDC, and the slf4j-ext module comes with
such an implementation. See
http://slf4j.org/xref/org/slf4j/NDC.html. Moreover, MDC fits most
problems better than NDC, but your use case might warrant NDC instead
of MDC.

With regards to the varargs, for one or two arguments there is no
need to create an Object array as SLF4J offers methods for one or two
arguments. Only for 3 or more arguments do you need to create an

Anyway, it's very nice to hear from you.


http://logback.qos.ch: The reliable, generic, fast and flexible logging

On 23/02/2010 7:14 PM, James A. N. Stauffer wrote:
> Thanks Ceki!
> Two of our projects use NDC so I'll probably leave them with log4j but
> I might switch the j.u.l calls to SLF4J.  I see that j.u.l does
> support parameterized messages but they don't use varargs so you have
> to explicitly create an extra Object[] and it requires you to pass the
> level.
> On Tue, Feb 23, 2010 at 11:16 AM, Ceki Gülcü<ceki@qos.ch>  wrote:
>> Hello James,
>> There is no perfect way to measure the overhead of parameter
>> constructions, but 200 nanosecond is a reasonable lower bound. So, if
>> you call a disabled logger 1'000'000 times you will see an overhead of
>> at least 200 milliseconds. Nothing to call home about. However, the
>> toString() methods of certain objects can be very costly so the impact
>> of parameter construction can be much higher than 200 nanos.
>> BTW, SLF4J handles this use case very nicely. Note that slf4-api.jar
>> is 23K in size and slf4j-jdk14.jar (which logs to java.util.logging)
>> is only 8K. If you were using the SLF4J API, you could instruct SLF4J
>> to delegate to java.util.logging via slf4j-jdk14.jar, solving the
>> overhead problem at the cost of additional 31K to download during
>> applet start up.
>> Moreover, if you were using SLF4J throughout your application, the
>> rest of your application could share code with the applet as both
>> the application and the applet would be using the same logging API. Your
>> application of course could continue to delegate logging to log4j as
>> you do currently.
>> HTH,
>> --
>> Ceki
>> http://logback.qos.ch: The reliable, generic, fast and flexible logging
>> framework.

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

View raw message