On Dec 9, 2008, at 4:58 AM, Thorbjørn Ravn Andersen wrote:
There was a request recently to make the argument replacement mechanism more powerful in either slf4j or logback (cannot remember) where Ceki mentioned that one of the major benefits of the {}- approach was that it was measurably faster than the StringFormatter in Java.

For this particular purpose I suggest that the fastest approach is chosen as it will apply to all events actually processed. Would lifting the slf4j code into log4j be an option - I believe that the license allows it.


There are two formatters in the Java API, java.text.MessageFormat (since JDK 1) and java.util.Formatter (since JDK 5). The SLF4J format specifier resembles, but is incompatible with, the format specifier of java.text.MessageFormat.

Actually the SLF4J formatting code (as far as I can tell) was originally written as part of log4j 1.3 and already is used in LogSF in the extras companion. LogMF provides the same services but uses java.text.MessageFormat format specifiers. While these were in the sandbox, there was a LogF which provided the same services using the java.util.Formatter, however their wasn't sufficient demand to polish that up for release. Still very doable.

LogMF and LogSF provided highly optimized message parameterization compatible with log4j 1.2.8 and later. Keeping message formatting distinct from the logger class allows supporting different formatters.

The supposed performance benefit of the SLF4J formatter over the java.text.MessageFormat only occurs when you compare the performance against naive use of java.text.MessageFormat. LogMF handles the simplest pattern specifications (those just involving {0}, {1}, etc) internally and only delegates to java.text.MessageFormat for more complex pattern specifications, resulting in equivalent performance to the SLF4J formatter on functionally equivalent format specifiers while still supporting the full java.text.MessageFormat capabilities.

This very early thread on slf4j-dev (http://marc.info/?l=slf4j-dev&m=112327572703543&w=2 ) discussed the potential use of java.text.MessageFormat pattern specifiers long before SLF4J was frozen.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to