public final class

FormattingLogger

extends Object
java.lang.Object
   ↳ com.google.gdata.util.common.logging.FormattingLogger

Class Overview

A wrapped logger chock-full of convenience methods. The introduction of varargs in Java 5 has provided two ways to further simplify logging information.

First, the level-based convenience methods such as Logger.foo(String msg) can contain an additional Object... args parameter that formats your message according to the logger's java.util.logging.Formatter.

Second, for those times when you don't want the java.util.logging.Formatter to manage formatting your message, you can use the FormattingLogger.xxxfmt(String fmt, Object... params) methods. These methods leverage the Java 5 String#format(String format, Object... args) method. However, logger.infofmt("%s %s", foo, bar) is slightly more efficient than logger.info(String.format("%s %s", foo, bar)) since the text is only formatted when the message is sufficiently important. It's also a little more readable.

Keep in mind that this class mixes two ways to format text: one that expects text to be formatted by the logger's java.util.logging.Formatter and one that depends upon the new format(java.lang.String, java.lang.Object[]) style. If, in this class, method name ends with fmt, it's formatting using the latter. If the class method does not end with fmt, it's using the traditional formatting style. NOTE(future extenders): any time a new logfmt(Level, String, Object...) variant is added to this class a matching logpfmt(Level, String, String, String, Object...) variant must also be added, and vice versa. This enables com.google.monitoring.runtime.instrumentation.LogFasterer to do its job. by calls to the private method doLog, which sets the resource bundle. FormattingLogger does not support that yet; this functionality may change.

Summary

Nested Classes
class FormattingLogger.Record An extension of LogRecord used to support a custom version of its private inferCaller(String) method. 
Fields
private static final String LOGGER_CLASS_NAME
private final Logger logger
Public Constructors
FormattingLogger(Class<?> cls)
Creates a new FormattingLogger.
FormattingLogger()
Creates a new FormattingLogger.
FormattingLogger(Logger logger)
Creates a new FormattingLogger by wrapping a Logger.
Public Methods
void config(String msg, Throwable thrown)
Log a CONFIG message.
void config(String msg, Object... params)
Log a CONFIG message.
void configfmt(String fmt, Object... args)
Log a CONFIG message.
void configfmt(Throwable thrown, String fmt, Object... args)
Log a CONFIG message.
void configfmt(String fmt, Throwable thrown)
Log a CONFIG message.
void fine(String msg, Object... params)
Log a FINE message.
void fine(String msg, Throwable thrown)
Log a FINE message.
void finefmt(String fmt, Object... args)
Log a FINE message.
void finefmt(Throwable thrown, String fmt, Object... args)
Log a FINE message.
void finefmt(String fmt, Throwable thrown)
Log a FINE message.
void finer(String msg, Object... params)
Log a FINER message.
void finer(String msg, Throwable thrown)
Log a FINER message.
void finerfmt(String fmt, Throwable thrown)
Log a FINER message.
void finerfmt(String fmt, Object... args)
Log a FINER message.
void finerfmt(Throwable thrown, String fmt, Object... args)
Log a FINER message.
void finest(String msg, Throwable thrown)
Log a FINEST message.
void finest(String msg, Object... params)
Log a FINEST message.
void finestfmt(String fmt, Throwable thrown)
Log a FINEST message.
void finestfmt(String fmt, Object... args)
Log a FINEST message.
void finestfmt(Throwable thrown, String fmt, Object... args)
Log a FINEST message.
Logger getFormattingLogger()
Gets the Logger wrapped by this FormattingLogger.
Level getLevel()
Pass-through to getLevel()
static FormattingLogger getLogger(String name)
Returns an instance of FormattingLogger.
static FormattingLogger getLogger(Class<?> cls)
Returns an instance of FormattingLogger using the getCanonicalName() as a source for the underlying logger's name.
void info(String msg, Throwable thrown)
Log an INFO message.
void info(String msg, Object... params)
Log an INFO message.
void infofmt(Throwable thrown, String fmt, Object... args)
Log a INFO message.
void infofmt(String fmt, Throwable thrown)
Log an INFO message.
void infofmt(String fmt, Object... args)
Log an INFO message.
boolean isLoggable(Level level)
Pass-through to isLoggable(Level)
void log(Level level, String msg, Object... params)
Similar to log(Level, String, Object[]), allows you to delay formatting with java.text.MessageFormat.
void log(Level level, String msg, Throwable thrown)
Similar to log(Level, String, Throwable), sets the value of getThrown().
void log(Level level, Throwable thrown, String msg, Object... params)
Similar to log(Level, String, Throwable), but takes variable arguments and allows you to delay formatting with java.text.MessageFormat.
void log(LogRecord lr)
Log a java.util.logging.LogRecord.
void logfmt(Level level, String fmt, Throwable thrown)
Log a message.
void logfmt(Level level, Throwable thrown, String fmt, Object... args)
Log a message.
void logfmt(Level level, String fmt, Object... args)
Log a message.
void logp(Level level, String sourceClassName, String sourceMethodName, Throwable thrown, String msg, Object... params)
Logs an event with a known context, similar to logp(java.util.logging.Level, String, String, String, Throwable).
void logp(Level level, String sourceClassName, String sourceMethodName, String msg, Throwable thrown)
Logs an event with a known context, similar to logp(java.util.logging.Level, String, String, String, Throwable).
void logp(Level level, String sourceClassName, String sourceMethodName, String msg, Object... params)
Logs an event with a known context, similar to logp(java.util.logging.Level, String, String, String).
void logpfmt(Level level, String sourceClassName, String sourceMethodName, String fmt, Object... args)
Logs an event with a known context, using explicit formatting rules.
void logpfmt(Level level, String sourceClassName, String sourceMethodName, String fmt, Throwable thrown)
Logs an event with a known context, using explicit formatting rules.
void logpfmt(Level level, String sourceClassName, String sourceMethodName, Throwable thrown, String fmt, Object... args)
Logs an event with a known context, using explicit formatting rules.
void setLevel(Level level)
Pass-through to setLevel(Level)
void severe(String msg, Throwable thrown)
Log a SEVERE message.
void severe(String msg, Object... params)
Log a SEVERE message, with an array of object arguments.
void severefmt(String fmt, Object... args)
Log a SEVERE message.
void severefmt(Throwable thrown, String fmt, Object... args)
Log a SEVERE message.
void severefmt(String fmt, Throwable thrown)
Log a SEVERE message.
void warning(String msg, Object... params)
Log a WARNING message.
void warning(String msg, Throwable thrown)
Log a WARNING message.
void warningfmt(String fmt, Throwable thrown)
Log a WARNING message.
void warningfmt(Throwable thrown, String fmt, Object... args)
Log a WARNING message.
void warningfmt(String fmt, Object... args)
Log a WARNING message.
[Expand]
Inherited Methods
From class java.lang.Object

Fields

private static final String LOGGER_CLASS_NAME

private final Logger logger

Public Constructors

public FormattingLogger (Class<?> cls)

Creates a new FormattingLogger. This is convenience ctor that creates a named backing Logger with the name of the passed-in class.

Parameters
cls The class whose name will be used to name the backing logger.

public FormattingLogger ()

Creates a new FormattingLogger. This is a convenience ctor that creates an anonymous backing Logger.

public FormattingLogger (Logger logger)

Creates a new FormattingLogger by wrapping a Logger.

Parameters
logger The Logger to wrap.

Public Methods

public void config (String msg, Throwable thrown)

Log a CONFIG message.

If the logger is currently enabled for the CONFIG message level then the given message is forwarded to all the registered output Handler objects.

Parameters
msg The string message (or a key in the message catalog)
thrown The throwable which triggered this log event, and parameter to the message

public void config (String msg, Object... params)

Log a CONFIG message.

If the logger is currently enabled for the CONFIG message level then the given message is forwarded to all the registered output Handler objects.

Parameters
msg The string message (or a key in the message catalog)
params Array of parameters to the message

public void configfmt (String fmt, Object... args)

Log a CONFIG message.

If the logger currently accepts messages of the supplied level, then the fmt and args are converted to a string using format(String, Object[]) and is forwarded to all the registered output Handler objects.

Parameters
fmt A format string
args Array of parameters to the formatter
See Also

public void configfmt (Throwable thrown, String fmt, Object... args)

Log a CONFIG message.

If the logger currently accepts messages of the supplied level, then the fmt and args are converted to a string using format(String, Object[]) and forwarded to all the registered output Handler objects.

Parameters
thrown The throwable which triggered this log event
fmt The string message (or a key in the message catalog)
args Array of parameters to the message

public void configfmt (String fmt, Throwable thrown)

Log a CONFIG message.

If the logger currently accepts messages of the supplied level, then the fmt and thrown are converted to a string using format(String, Object[]) and is forwarded to all the registered output Handler objects.

Parameters
fmt A format string
thrown The throwable which triggered this log event, and parameter to the formatter message
See Also

public void fine (String msg, Object... params)

Log a FINE message.

If the logger is currently enabled for the FINE message level then the given message is forwarded to all the registered output Handler objects.

Parameters
msg The string message (or a key in the message catalog)
params Array of parameters to the message

public void fine (String msg, Throwable thrown)

Log a FINE message.

If the logger is currently enabled for the FINE message level then the given message is forwarded to all the registered output Handler objects.

Parameters
msg The string message (or a key in the message catalog)
thrown The throwable which triggered this log event, and parameter to the message

public void finefmt (String fmt, Object... args)

Log a FINE message.

If the logger currently accepts messages of the supplied level, then the fmt and args are converted to a string using format(String, Object[]) and is forwarded to all the registered output Handler objects.

Parameters
fmt A format string
args Array of parameters to the formatter
See Also

public void finefmt (Throwable thrown, String fmt, Object... args)

Log a FINE message.

If the logger currently accepts messages of the supplied level, then the fmt and args are converted to a string using format(String, Object[]) and forwarded to all the registered output Handler objects.

Parameters
thrown The throwable which triggered this log event
fmt The string message (or a key in the message catalog)
args Array of parameters to the message

public void finefmt (String fmt, Throwable thrown)

Log a FINE message.

If the logger currently accepts messages of the supplied level, then the fmt and thrown are converted to a string using format(String, Object[]) and is forwarded to all the registered output Handler objects.

Parameters
fmt A format string
thrown The throwable which triggered this log event, and parameter to the formatter message
See Also

public void finer (String msg, Object... params)

Log a FINER message.

If the logger is currently enabled for the FINER message level then the given message is forwarded to all the registered output Handler objects.

Parameters
msg The string message (or a key in the message catalog)
params Array of parameters to the message

public void finer (String msg, Throwable thrown)

Log a FINER message.

If the logger is currently enabled for the FINER message level then the given message is forwarded to all the registered output Handler objects.

Parameters
msg The string message (or a key in the message catalog)
thrown The throwable which triggered this log event, and parameter to the message

public void finerfmt (String fmt, Throwable thrown)

Log a FINER message.

If the logger currently accepts messages of the supplied level, then the fmt and thrown are converted to a string using format(String, Object[]) and is forwarded to all the registered output Handler objects.

Parameters
fmt A format string
thrown The throwable which triggered this log event, and parameter to the formatter message
See Also

public void finerfmt (String fmt, Object... args)

Log a FINER message.

If the logger currently accepts messages of the supplied level, then the fmt and args are converted to a string using format(String, Object[]) and is forwarded to all the registered output Handler objects.

Parameters
fmt A format string
args Array of parameters to the formatter
See Also

public void finerfmt (Throwable thrown, String fmt, Object... args)

Log a FINER message.

If the logger currently accepts messages of the supplied level, then the fmt and args are converted to a string using format(String, Object[]) and forwarded to all the registered output Handler objects.

Parameters
thrown The throwable which triggered this log event
fmt The string message (or a key in the message catalog)
args Array of parameters to the message

public void finest (String msg, Throwable thrown)

Log a FINEST message.

If the logger is currently enabled for the FINEST message level then the given message is forwarded to all the registered output Handler objects.

Parameters
msg The string message (or a key in the message catalog)
thrown The throwable which triggered this log event, and parameter to the message

public void finest (String msg, Object... params)

Log a FINEST message.

If the logger is currently enabled for the FINEST message level then the given message is forwarded to all the registered output Handler objects.

Parameters
msg The string message (or a key in the message catalog)
params Array of parameters to the message

public void finestfmt (String fmt, Throwable thrown)

Log a FINEST message.

If the logger currently accepts messages of the supplied level, then the fmt and thrown are converted to a string using format(String, Object[]) and is forwarded to all the registered output Handler objects.

Parameters
fmt A format string
thrown The throwable which triggered this log event, and parameter to the formatter message
See Also

public void finestfmt (String fmt, Object... args)

Log a FINEST message.

If the logger currently accepts messages of the supplied level, then the fmt and args are converted to a string using format(String, Object[]) and is forwarded to all the registered output Handler objects.

Parameters
fmt A format string
args Array of parameters to the formatter
See Also

public void finestfmt (Throwable thrown, String fmt, Object... args)

Log a FINEST message.

If the logger currently accepts messages of the supplied level, then the fmt and args are converted to a string using format(String, Object[]) and forwarded to all the registered output Handler objects.

Parameters
thrown The throwable which triggered this log event
fmt The string message (or a key in the message catalog)
args Array of parameters to the message

public Logger getFormattingLogger ()

Gets the Logger wrapped by this FormattingLogger.

Returns
  • the Logger wrapped by this FormattingLogger.

public Level getLevel ()

Pass-through to getLevel()

public static FormattingLogger getLogger (String name)

Returns an instance of FormattingLogger.

Parameters
name

public static FormattingLogger getLogger (Class<?> cls)

Returns an instance of FormattingLogger using the getCanonicalName() as a source for the underlying logger's name.

Parameters
cls

public void info (String msg, Throwable thrown)

Log an INFO message.

If the logger is currently enabled for the INFO message level then the given message is forwarded to all the registered output Handler objects.

Parameters
msg The string message (or a key in the message catalog)
thrown The throwable which triggered this log event, and parameter to the message

public void info (String msg, Object... params)

Log an INFO message.

If the logger is currently enabled for the INFO message level then the given message is forwarded to all the registered output Handler objects.

Parameters
msg The string message (or a key in the message catalog)
params Array of parameters to the message

public void infofmt (Throwable thrown, String fmt, Object... args)

Log a INFO message.

If the logger currently accepts messages of the supplied level, then the fmt and args are converted to a string using format(String, Object[]) and forwarded to all the registered output Handler objects.

Parameters
thrown The throwable which triggered this log event
fmt The string message (or a key in the message catalog)
args Array of parameters to the message

public void infofmt (String fmt, Throwable thrown)

Log an INFO message.

If the logger currently accepts messages of the supplied level, then the fmt and thrown are converted to a string using format(String, Object[]) and is forwarded to all the registered output Handler objects.

Parameters
fmt A format string
thrown The throwable which triggered this log event, and parameter to the formatter message
See Also

public void infofmt (String fmt, Object... args)

Log an INFO message.

If the logger currently accepts messages of the supplied level, then the fmt and args are converted to a string using format(String, Object[]) and is forwarded to all the registered output Handler objects.

Parameters
fmt A format string
args Array of parameters to the formatter
See Also

public boolean isLoggable (Level level)

Pass-through to isLoggable(Level)

Parameters
level

public void log (Level level, String msg, Object... params)

Similar to log(Level, String, Object[]), allows you to delay formatting with java.text.MessageFormat.

Parameters
level
msg
params

public void log (Level level, String msg, Throwable thrown)

Similar to log(Level, String, Throwable), sets the value of getThrown().

Parameters
level
msg
thrown

public void log (Level level, Throwable thrown, String msg, Object... params)

Similar to log(Level, String, Throwable), but takes variable arguments and allows you to delay formatting with java.text.MessageFormat. Calls setThrown(Throwable) if thrown is non-null.

Parameters
level
thrown
msg
params

public void log (LogRecord lr)

Log a java.util.logging.LogRecord. The log message, level and other parameters are contained in the LogRecord, but the source class and method will be set if necessary.

Parameters
lr

public void logfmt (Level level, String fmt, Throwable thrown)

Log a message.

If the logger currently accepts messages of the supplied level, then the fmt and thrown are converted to a string using format(String, Object[]) and forwarded to all the registered output Handler objects.

Parameters
level One of the message level identifiers, e.g. SEVERE
fmt The string message (or a key in the message catalog)
thrown The throwable which triggered this log event, and parameter to the format message

public void logfmt (Level level, Throwable thrown, String fmt, Object... args)

Log a message.

If the logger currently accepts messages of the supplied level, then the fmt and args are converted to a string using format(String, Object[]) and forwarded to all the registered output Handler objects.

Parameters
level One of the message level identifiers, e.g. SEVERE
thrown The throwable which triggered this log event
fmt The string message (or a key in the message catalog)
args Array of parameters to the message

public void logfmt (Level level, String fmt, Object... args)

Log a message.

If the logger currently accepts messages of the supplied level, then the fmt and args are converted to a string using format(String, Object[]) and forwarded to all the registered output Handler objects.

Parameters
level One of the message level identifiers, e.g. SEVERE
fmt The string message (or a key in the message catalog)
args Array of parameters to the message

public void logp (Level level, String sourceClassName, String sourceMethodName, Throwable thrown, String msg, Object... params)

Logs an event with a known context, similar to logp(java.util.logging.Level, String, String, String, Throwable). However, this delays formatting of the message.

Parameters
level One of the message level identifiers, e.g. SEVERE
sourceClassName The class generating this log event
sourceMethodName The method generating this log event
thrown The throwable which triggered this log event
msg The basic message string
params The parameters for the message string

public void logp (Level level, String sourceClassName, String sourceMethodName, String msg, Throwable thrown)

Logs an event with a known context, similar to logp(java.util.logging.Level, String, String, String, Throwable). However, this delays formatting of the message.

Parameters
level One of the message level identifiers, e.g. SEVERE
sourceClassName The class generating this log event
sourceMethodName The method generating this log event
msg The message string
thrown The throwable which triggered this log event

public void logp (Level level, String sourceClassName, String sourceMethodName, String msg, Object... params)

Logs an event with a known context, similar to logp(java.util.logging.Level, String, String, String). However, this delays formatting of the message.

Parameters
level One of the message level identifiers, e.g. SEVERE
sourceClassName The class generating this log event
sourceMethodName The method generating this log event
msg The basic message string
params The parameters for the message string

public void logpfmt (Level level, String sourceClassName, String sourceMethodName, String fmt, Object... args)

Logs an event with a known context, using explicit formatting rules.

If the logger currently accepts messages of the supplied level, then the fmt and args are converted to a string using format(String, Object[]) and forwarded to all the registered output Handler objects.

Parameters
level One of the message level identifiers, e.g. SEVERE
sourceClassName The class generating this log event
sourceMethodName The method generating this log event
fmt The string message (or a key in the message catalog)
args Array of parameters to the format message

public void logpfmt (Level level, String sourceClassName, String sourceMethodName, String fmt, Throwable thrown)

Logs an event with a known context, using explicit formatting rules.

If the logger currently accepts messages of the supplied level, then the fmt and thrown are converted to a string using format(String, Object[]) and forwarded to all the registered output Handler objects.

Parameters
level One of the message level identifiers, e.g. SEVERE
sourceClassName The class generating this log event
sourceMethodName The method generating this log event
fmt The string message (or a key in the message catalog)
thrown The throwable which triggered this log event, and parameter to the format message

public void logpfmt (Level level, String sourceClassName, String sourceMethodName, Throwable thrown, String fmt, Object... args)

Logs an event with a known context, using explicit formatting rules.

If the logger currently accepts messages of the supplied level, then the fmt and args are converted to a string using format(String, Object[]) and forwarded to all the registered output Handler objects.

Parameters
level One of the message level identifiers, e.g. SEVERE
sourceClassName The class generating this log event
sourceMethodName The method generating this log event
thrown The throwable which triggered this log event
fmt The string message (or a key in the message catalog)
args Array of parameters to the message

public void setLevel (Level level)

Pass-through to setLevel(Level)

Parameters
level

public void severe (String msg, Throwable thrown)

Log a SEVERE message.

If the logger is currently enabled for the SEVERE message level then the given message is forwarded to all the registered output Handler objects.

Parameters
msg The string message (or a key in the message catalog)
thrown The throwable which triggered this log event, and parameter to the message

public void severe (String msg, Object... params)

Log a SEVERE message, with an array of object arguments.

If the logger is currently enabled for the SEVERE message level then the given message is forwarded to all the registered output Handler objects.

Parameters
msg The string message (or a key in the message catalog)
params Array of parameters to the message

public void severefmt (String fmt, Object... args)

Log a SEVERE message.

If the logger currently accepts messages of the supplied level, then the fmt and args are converted to a string using format(String, Object[]) and is forwarded to all the registered output Handler objects.

Parameters
fmt A format string
args Array of parameters to the formatter
See Also

public void severefmt (Throwable thrown, String fmt, Object... args)

Log a SEVERE message.

If the logger currently accepts messages of the supplied level, then the fmt and args are converted to a string using format(String, Object[]) and forwarded to all the registered output Handler objects.

Parameters
thrown The throwable which triggered this log event
fmt The string message (or a key in the message catalog)
args Array of parameters to the message

public void severefmt (String fmt, Throwable thrown)

Log a SEVERE message.

If the logger currently accepts messages of the supplied level, then the fmt and thrown are converted to a string using format(String, Object[]) and is forwarded to all the registered output Handler objects.

Parameters
fmt A format string
thrown The throwable which triggered this log event, and parameter to the formatter message
See Also

public void warning (String msg, Object... params)

Log a WARNING message.

If the logger is currently enabled for the WARNING message level then the given message is forwarded to all the registered output Handler objects.

Parameters
msg The string message (or a key in the message catalog)
params Array of parameters to the message

public void warning (String msg, Throwable thrown)

Log a WARNING message.

If the logger is currently enabled for the WARNING message level then the given message is forwarded to all the registered output Handler objects.

Parameters
msg The string message (or a key in the message catalog)
thrown The throwable which triggered this log event, and parameter to the message

public void warningfmt (String fmt, Throwable thrown)

Log a WARNING message.

If the logger currently accepts messages of the supplied level, then the fmt and thrown are converted to a string using format(String, Object[]) and is forwarded to all the registered output Handler objects.

Parameters
fmt A format string
thrown The throwable which triggered this log event, and parameter to the formatter message
See Also

public void warningfmt (Throwable thrown, String fmt, Object... args)

Log a WARNING message.

If the logger currently accepts messages of the supplied level, then the fmt and args are converted to a string using format(String, Object[]) and forwarded to all the registered output Handler objects.

Parameters
thrown The throwable which triggered this log event
fmt The string message (or a key in the message catalog)
args Array of parameters to the message

public void warningfmt (String fmt, Object... args)

Log a WARNING message.

If the logger currently accepts messages of the supplied level, then the fmt and args are converted to a string using format(String, Object[]) and is forwarded to all the registered output Handler objects.

Parameters
fmt A format string
args Array of parameters to the formatter
See Also