Thorbjørn Ravn Andersen wrote:
Ceki Gulcu skrev  den 12-12-2008 16:01:
To run this test, in addition to junit4.jar, you need to have
slf4j-api.jar, apache-log4j-extras-1.1-SNAPSHOT.jar and log4j.jar on
your class path.

On my machine the output is:
LogMF avg=15251
SLF4J avg=4964


On my machine (which is low on RAM) I get these numbers with JDK 1.5

SLF4J avg=6085
LogMF avg=12582

I understand how you get the LogMF method to write to ytest.log, but not how the slf4j method does it.
Would you care to elaborate?

Sure. SLF4J delegates to log4j (via slf4j-log4j12.jar). I now realize
that the instructions in my mail of 12-12-2008 did not mention
slf4j-log4j12.jar. Did you add slf4j-log4j12.jar to your class path?

To check that the testSLF4J actually writes to ytest.log via log4j,
disable "testLogMF()" by adding the @Ignore annotation before the
testLogMF() method. You should see that ytest.log file increases in
size as testSLF4J() logs into it via log4j, as it should. (If you have
any lingering doubts that log4j is the underlying framework, you can
run the tests in a debugger.)

This shows that an enabled logging statement runs three times faster
when logging via SLF4J than when logging through LogMF, with log4j as
the underlying logging framework. Not only is the SLF4J formatter
faster, it makes a "noticeable" difference when the logs are actually
written to destination.

This is a very substantial difference, so if the LogMF approach is to be used some kind of mechanism should be used to optimize - a weak reference cache of the MessageFormatter with the format string as key - but if the simpler approach is faster I would personally go with that.


--
Ceki Gülcü

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

Reply via email to