On Feb 10, 2008, at 8:35 PM, Katherine Hale wrote:
Curt -
Thanks for the fly-by-night introduction. This is what I was
thinking in more detail. Again I know this is Java 5, so this would
be for Log4J 2.0, although perhaps something comparable could be
devised for the current Log4J. I'll just use debug as an example.
I find myself frequently logging like this...
Logger.debug(String.format("First object '%s', second object '%s'",
first, second));
When I wish I could just be logging like this..
Logger.debug("First object '%s', second object '%s'", first, second);
The new signature I feel is missing would be something like this...
public static debug(String message, String ... arguments)
After briefly looking at LogMF, this might be doing the same thing.
I'm not familiar with MessageFormat, so I don't know if the usage
for the "pattern" argument is the same or different from
String.format() in Java 5.
352 /***
353 * Log a parameterized message at debug level.
354 * @param logger logger, may not be null.
355 * @param pattern pattern, may be null.
356 * @param arguments an array of arguments to be formatted and
substituted.
357 */
358 public static void debug(final Logger logger, final String
pattern,
359 final Object[] arguments) {
360 if (logger.isDebugEnabled()) {
361 forcedLog(logger, Level.DEBUG, format(pattern, arguments));
362 }
363 }
Thoughts?
String.format() is an indirect call to the java.util.Formatter class
that was introduced in JDK 1.5. The LogF class that was started at
the same time as LogMF and LogSF but not driven through to release
used java.util.Formatter. It is still in the SVN history and could be
brought forward, but LogSF and LogMF were more immediately useful.
LogSF was provided as a migration path for the log4j 1.3 message
formatter which had a syntax similar to, but incompatible with with
java.text.MessageFormat. There is no reason to use LogSF in new code.
Your logging statement could look like:
LogMF.debug(logger, "First object '{0}', second object '{1}'", first,
second);
or
LogF.debug(logger, "First object '%s', second object '%s'", first,
second);
Since there are two distinct formatters provided in the JDK, it would
be undesirable for log4j to pick one over the other (or worse yet to
introduce yet another pattern syntax).
LogMF avoids the construction of the Object[] array until the
threshold is evaluated which a varargs approach would not do unless
the JVM was able to detect the array was not going to be used.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]