org.geotools.util
Class MonolineFormatter

java.lang.Object
  extended byjava.util.logging.Formatter
      extended byorg.geotools.util.MonolineFormatter

public class MonolineFormatter
extends java.util.logging.Formatter

A formatter writting log messages on a single line. This formatter is used by Geotools 2 instead of SimpleFormatter. The main difference is that this formatter use only one line per message instead of two. For example, a message formatted by looks like:

 FINE core - A log message logged with level FINE from the "org.geotools.core" logger.
 
By default, display only the level and the message. Additional fields can be formatted if setTimeFormat(java.lang.String) or setSourceFormat(java.lang.String) methods are invoked with a non-null argument. The format can also be set from the file. For example, user can cut and paste the following properties into :
 ############################################################
 # Properties for the Geotools's MonolineFormatter.
 # By default, the monoline formatter display only the level
 # and the message. Additional fields can be specified here:
 #
 #   time:  If set, writes the time ellapsed since the initialization.
 #          The argument specifies the output pattern. For example, the
 #          pattern HH:mm:ss.SSSS display the hours, minutes, seconds
 #          and milliseconds.
 #
 #  source: If set, writes the source logger or the source class name.
 #          The argument specifies the type of source to display. Valid
 #          values are none, logger:short, logger:long, class:short and
 #          class:long.
 ############################################################
 org.geotools.util.MonolineFormatter.time = HH:mm:ss.SSS
 org.geotools.util.MonolineFormatter.source = class:short
 
If the is wanted for the whole system (not just the packages) with level FINE (for example), then the following properties can be defined as below:
 java.util.logging.ConsoleHandler.formatter = org.geotools.util.MonolineFormatter
 java.util.logging.ConsoleHandler.encoding = Cp850
 java.util.logging.ConsoleHandler.level = FINE
 

Since:
2.0
Version:
$Id: MonolineFormatter.java 17672 2006-01-19 00:25:55Z desruisseaux $
Author:
Martin Desruisseaux

Constructor Summary
MonolineFormatter()
          Construct a default .
MonolineFormatter(java.lang.String base)
          Construct a .
 
Method Summary
 java.lang.String format(java.util.logging.LogRecord record)
          Format the given log record and return the formatted string.
 java.lang.String getSourceFormat()
          Returns the format for displaying the source.
 java.lang.String getTimeFormat()
          Returns the format for displaying ellapsed time.
static MonolineFormatter init(java.lang.String base)
          Setup a for the specified logger and its children.
static MonolineFormatter init(java.lang.String base, java.util.logging.Level level)
          Convenience method setting both a and the logger levels.
static void initGeotools()
          Initialise the formatter for the "" loggers.
static void initGeotools(java.util.logging.Level level)
          Initialise the formatter for the "" loggers with the specified level.
 void setSourceFormat(java.lang.String format)
          Set the format for displaying the source.
 void setTimeFormat(java.lang.String pattern)
          Set the format for displaying ellapsed time.
 
Methods inherited from class java.util.logging.Formatter
formatMessage, getHead, getTail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MonolineFormatter

public MonolineFormatter()
Construct a default .


MonolineFormatter

public MonolineFormatter(java.lang.String base)
Construct a .

Parameters:
base - The base logger name. This is used for shortening the logger name when formatting message. For example, if the base logger name is "org.geotools" and a log record come from the "org.geotools.core" logger, it will be formatted as "[LEVEL core]" (i.e. the "org.geotools" part is ommited).
Method Detail

setTimeFormat

public void setTimeFormat(java.lang.String pattern)
Set the format for displaying ellapsed time. The pattern must matches the format specified in SimpleDateFormat. For example, the pattern "HH:mm:ss.SSS" will display the ellapsed time in hours, minutes, seconds and milliseconds.

Parameters:
pattern - The time patter, or to disable time formatting.

getTimeFormat

public java.lang.String getTimeFormat()
Returns the format for displaying ellapsed time. This is the pattern specified to the last call to setTimeFormat(java.lang.String), or the patten specified in the property in the file.

Returns:
The time pattern, or if time is not formatted.

setSourceFormat

public void setSourceFormat(java.lang.String format)
Set the format for displaying the source. The pattern may be one of the following: "none", "logger:short", "class:short", "logger:long" or "class:long". The difference between a and "none" is that may be replaced by a default value, while "none" means that the user explicitly requested no source.

Parameters:
format - The format for displaying the source, or to disable source formatting.

getSourceFormat

public java.lang.String getSourceFormat()
Returns the format for displaying the source. This is the pattern specified to the last call to setSourceFormat(java.lang.String), or the patten specified in the property in the file.

Returns:
The source pattern, or if source is not formatted.

format

public java.lang.String format(java.util.logging.LogRecord record)
Format the given log record and return the formatted string.

Parameters:
record - the log record to be formatted.
Returns:
a formatted log record

init

public static MonolineFormatter init(java.lang.String base)
Setup a for the specified logger and its children. This method search for all instances of ConsoleHandler using the SimpleFormatter. If such instances are found, they are replaced by a single instance of writting to the standard output stream (instead of the standard error stream). If no such ConsoleHandler are found, then a new one is created with this . This action has no effect on any loggers outside the namespace.

Parameters:
base - The base logger name to apply the change on (e.g. "org.geotools").
Returns:
The registered (never ). The formatter output can be configured using the setTimeFormat(java.lang.String) and setSourceFormat(java.lang.String) methods.

init

public static MonolineFormatter init(java.lang.String base,
                                     java.util.logging.Level level)
Convenience method setting both a and the logger levels. This method behave like init(String), except that it accepts an optional level argument. If the level is non-null, then all Handlers using the monoline formatter will be set to the specified level. The logger named will also be set to this level.

Note: Avoid this method as much as possible, since it overrides user's level setting for the logger. A user trying to configure its logging properties may find confusing to see his setting ignored.

Parameters:
base - The base logger name to apply the change on (e.g. "org.geotools").
level - The desired level, or if no level should be set.
Returns:
The registered (never ). The formatter output can be configured using the setTimeFormat(java.lang.String) and setSourceFormat(java.lang.String) methods.

initGeotools

public static void initGeotools()
Initialise the formatter for the "" loggers.


initGeotools

public static void initGeotools(java.util.logging.Level level)
Initialise the formatter for the "" loggers with the specified level. NOTE: Avoid this method as much as possible, since it overrides user's level setting for the "" logger. A user trying to configure its logging properties may find confusing to see his setting ignored.

Parameters:
level - The logging level, or if no level should be set.


Copyright © GeoTools. All Rights Reserved.