[slf4j-dev] [Bug 116] Switching the log message format to that of java.util.Formatter

bugzilla-daemon at pixie.qos.ch bugzilla-daemon at pixie.qos.ch
Tue Dec 2 17:31:49 CET 2008


http://bugzilla.slf4j.org/show_bug.cgi?id=116





--- Comment #17 from Ken Dobson <ken at magictractor.co.uk>  2008-12-02 17:31:48 ---
Created an attachment (id=48)
 --> (http://bugzilla.slf4j.org/attachment.cgi?id=48)
Proposed patch

Grzegorz is right, the term "decorator" is wrong. "Adaptor" isn't accurate
either, so I have avoided both terms, and opted for FormatModifier.

I have attached a patch. To use the new code, get a logger from XLoggerFactory,
passing in a FormatModifier, such as:

Logger logger = XLoggerFactory.getXLogger(this.getClass(), new
JavaUtilFormattingFormatModifier());

Then use the logger as normal, but use java.util.Formatting style formatting,
such as:

logger.debug("Account balance %(,.2f", balance);


I have identified some areas which need some consideration:

* Names of new classes and methods.

* I have escaped any remaining formatting anchors ("{}") in the text after
applying java.util.Formatting. Without the escape, the wrapped logger would
perform further substitutions. Mixing formatters could be confusing; but maybe
it could be useful. Perhaps we should make it configurable?

* I have used some code which appeared in Java 1.5. I wasn't sure about this,
but XLogger already uses StringBuilder, so I used StringBuilder and
String.replace(). 

* It would be good to have unit tests which exercise FormatModifyingXLogger and
LoggerWrapper. There's a lot of scope for silly little mistakes in these
classes.

* I added unit tests to the dummyExt package, they should maybe be in an ext
package, with only XLogger tests in dummyExt

* Should we create a subpackage of org.slf4j.ext? If we provide more
implementations of FormatModifier and add new ideas to slf4j-ext then
org.slf4j.ext could quickly become cluttered.

* Should we log an additional warning if there is an Exception thrown by a
FormatModifier? See FormatModifyingXLogger.modify(String, Object[]).

* I haven't added code headers to the new classes. There are no headers in most
of the existing classes in the package.

* I think XLoggerTest should have log4jRoot.removeAllAppenders() added to its
tearDown() method.


-- 
Configure bugmail: http://bugzilla.slf4j.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.



More information about the slf4j-dev mailing list