com.sun.grid.jgdi.util
Class SGEFormatter

java.lang.Object
  extended by java.util.logging.Formatter
      extended by com.sun.grid.jgdi.util.SGEFormatter

public class SGEFormatter
extends java.util.logging.Formatter

This Formater formats LogRecords into one line. What columns and delimiters are formated can be configured. The default format is
<date>|<host>|<source method>|<level>| <message>

If the withStacktrace flag is set, the stacktrace of a logged excpetion is also included.

Example

     Logger logger = Logger.getLogger("test logger");

     ConsoleHandler consoleHandler = new ConsoleHandler();
     SGEFormatter  formatter = new SGEFormatter("test formatter");

     int columns [] = {
       SGEFormatter.COL_LEVEL_LONG, SGEFormatter.COL_MESSAGE
     };
     formatter.setColumns(columns);
     formatter.setDelimiter(":");

     consoleHandler.setFormatter(formatter);
     logger.addHandler(consoleHandler);
     logger.setUseParentHandlers(false);

  
This example will create log entries with the following format:
   <log level>:<message>
  


Nested Class Summary
static class SGEFormatter.Column
           
 
Field Summary
static int COL_HOST
          This column contains the hostname.
static int COL_LEVEL
          This column contains the log level of the log record in a short form (S, I, D).
static int COL_LEVEL_LONG
          This columns contains the log level of the log record in it's log form.
static int COL_MESSAGE
          This column the log message.
static int COL_NAME
          This columns contains the name of the SGEFormatter.
static int COL_SOURCE
          This column contains the source class and source method name which produces the log message.
static int COL_THREAD
          This column contains the thread ID of the log record.
static int COL_TIME
          This column contains the timestamp of the log record.
static int[] DEFAULT_COLUMNS
          The default columns are COL_TIME, COL_HOST, COL_SOURCE, COL_LEVEL, COL_MESSAGE.
 
Constructor Summary
SGEFormatter()
           
SGEFormatter(java.lang.String aName)
          Create a new SGEFormatter.
SGEFormatter(java.lang.String aName, boolean withStackTrace)
          Create a new SGEFormatter.
SGEFormatter(java.lang.String aName, boolean withStackTrace, int[] aColumns)
          Create a new SGEFormatter.
 
Method Summary
 java.lang.String format(java.util.logging.LogRecord record)
          format a log Record.
static SGEFormatter.Column getColumn(java.lang.String name)
           
 boolean getWithStackTrace()
          get the withStackTrace flag.
 void setColumns(int[] aColumns)
          set the columns for the formatter.
 void setDelimiter(java.lang.String aDelimiter)
          set the delimiter.
 void setWithStackTrace(boolean withStackTrace)
          set the withStackTrace flag.
 
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
 

Field Detail

COL_TIME

public static final int COL_TIME
This column contains the timestamp of the log record.

See Also:
Constant Field Values

COL_HOST

public static final int COL_HOST
This column contains the hostname.

See Also:
Constant Field Values

COL_NAME

public static final int COL_NAME
This columns contains the name of the SGEFormatter.

See Also:
Constant Field Values

COL_THREAD

public static final int COL_THREAD
This column contains the thread ID of the log record.

See Also:
Constant Field Values

COL_LEVEL

public static final int COL_LEVEL
This column contains the log level of the log record in a short form (S, I, D).

See Also:
Constant Field Values

COL_MESSAGE

public static final int COL_MESSAGE
This column the log message.

See Also:
Constant Field Values

COL_SOURCE

public static final int COL_SOURCE
This column contains the source class and source method name which produces the log message.

See Also:
Constant Field Values

COL_LEVEL_LONG

public static final int COL_LEVEL_LONG
This columns contains the log level of the log record in it's log form.

See Also:
Level.toString(), Constant Field Values

DEFAULT_COLUMNS

public static final int[] DEFAULT_COLUMNS
The default columns are COL_TIME, COL_HOST, COL_SOURCE, COL_LEVEL, COL_MESSAGE.

Constructor Detail

SGEFormatter

public SGEFormatter(java.lang.String aName)
Create a new SGEFormatter.

Parameters:
aName - name of the formatter

SGEFormatter

public SGEFormatter(java.lang.String aName,
                    boolean withStackTrace)
Create a new SGEFormatter.

Parameters:
aName - name of the formatter
withStackTrace - include the stacktrace

SGEFormatter

public SGEFormatter(java.lang.String aName,
                    boolean withStackTrace,
                    int[] aColumns)
Create a new SGEFormatter.

Parameters:
aName - name of the formatter
withStackTrace - include the stacktrace
aColumns - visible columns

SGEFormatter

public SGEFormatter()
Method Detail

getColumn

public static SGEFormatter.Column getColumn(java.lang.String name)

setDelimiter

public final void setDelimiter(java.lang.String aDelimiter)
set the delimiter.

Parameters:
aDelimiter - the new delimiter

setColumns

public final void setColumns(int[] aColumns)
set the columns for the formatter.

Parameters:
aColumns - the columns

setWithStackTrace

public final void setWithStackTrace(boolean withStackTrace)
set the withStackTrace flag.

Parameters:
withStackTrace - the new value of the flag

getWithStackTrace

public final boolean getWithStackTrace()
get the withStackTrace flag.

Returns:
the withStackTrace flag

format

public final java.lang.String format(java.util.logging.LogRecord record)
format a log Record.

Attention: This method is not thread safe

Specified by:
format in class java.util.logging.Formatter
See Also:
Formatter.format(java.util.logging.LogRecord)


Copyright © 2007 Sun Microsystems, Inc. All rights reserved.