logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gary Gregory <garydgreg...@gmail.com>
Subject [LOG4J2-133] part 2: LogManager API
Date Fri, 07 Dec 2012 22:21:29 GMT
I've attached to LOG4J2-133 a part 2 diff file.

This gives us a way to pass a MessageFactory to new
getLogger(String|Class|Object, MessageFactory) APIs.

For example:

        TestLogger testLogger = (TestLogger)
                new StringFormatterMessageFactory());
        testLogger.debug("%,d", Integer.MAX_VALUE);
        assertEquals(1, testLogger.getEntries().size());
        assertEquals(String.format(" DEBUG %,d", Integer.MAX_VALUE),

When you call getLogger(String|Class|Object), you get a Logger back, if
there is not one, it is created.

Now we have new APIs with a MessageFactory parameter. This parameter is
only used when creating the logger, which means it is only used the first
time the API is called.

If you subsequently call getLogger for the same logger, the MessageFactory
is ignored.

When the Logger is created, the MessageFactory is saved in a final ivar

I did not document this in the API yet but I plan on doing so.

Does anyone see a better way than documentation to deal with this?

Should a warning be logged if you call getLogger with a message factory
that is different than the one already set?

Thank you,

E-Mail: garydgregory@gmail.com | ggregory@apache.org
JUnit in Action, 2nd Ed: <http://goog_1249600977>http://bit.ly/ECvg0
Spring Batch in Action: <http://s.apache.org/HOq>http://bit.ly/bqpbCK
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

View raw message