I'm sure the timing sucks, but since the scuttling of the 1.2.10 release involves formatting log messages and I have recently been doing some things in the log4j sandbox, I thought that I would bring that work to your attention. The project can be checked out from http://svn.apache.org/repos/asf/logging/sandbox/log4j/formatter.

One of the problems with adding formatting to the Logger class in log4j is that there are several widely used formatting conventions: java.text.MessageFormat has been in Java for quite some time, java.util.Formatter was just added in JDK 1.5 (similar to C's sprintf) and the UGLI/SLF4J effort added a syntax similar but distinct to MessageFormat (org.apache.log4j.helpers.MessageFormatter). Currently the log4j code uses both java.text.MessageFormat (in the l7dlog methods) and o.a.l.helpers.MessageFormatter (in the debug(String fmt, ...) methods.

The sandbox effort intention was to remove formatting from the Logger class and to allow the user to pick the formatter of their choice, while still being able to bypass argument boxing, array creation and formatting on calls below the threshold. The formatter project adds three static classes LogMF, LogSF and LogF which log using the java.text.MessageFormat, UGLI/SLF4J formatter and java.util.Formatter respectively. In use the code would look like:

LogMF.debug(logger, "User {0} logged out after {1} seconds", username, duration);

The original discussion can be read at http://marc.theaimsgroup.com/? l=log4j-dev&m=113704872508753&w=2

I don't know the pattern syntax of the .NET formatter in use. If it is similar to one of the Java formatters, then I would use the corresponding class name. Otherwise, I would choose a slightly different name in case we ever wanted to emulate one of the Java formatters in .NET (actually, you might already be able to use java.text.MessageFormat from J#).

p.s. I had intended to add ResourceBundle variants of the methods with signatures like:

static void debug(Logger logger, ResourceBundle bundle, String fmtKey, ...);


Reply via email to