Log4j 0.9.1

org.log4j
Class TTCCLayout

java.lang.Object
  |
  +--org.log4j.Layout
        |
        +--org.log4j.helpers.DateLayout
              |
              +--org.log4j.TTCCLayout
All Implemented Interfaces:
OptionHandler

public class TTCCLayout
extends DateLayout

TTCC layout format consists of time, thread, category and nested diagnostic context information, hence the name.

Each of the four fields can be individually enabled or disabled. The time format depends on the DateFormat used.

Here is an example TTCCLayout output with the RelativeTimeDateFormat.

176 [main] INFO  org.log4j.examples.Sort - Populating an array of 2 elements in reverse order.
225 [main] INFO  org.log4j.examples.SortAlgo - Entered the sort method.
262 [main] DEBUG org.log4j.examples.SortAlgo.OUTER i=1 - Outer loop.
276 [main] DEBUG org.log4j.examples.SortAlgo.SWAP i=1 j=0 - Swapping intArray[0] = 1 and intArray[1] = 0
290 [main] DEBUG org.log4j.examples.SortAlgo.OUTER i=0 - Outer loop.
304 [main] INFO  org.log4j.examples.SortAlgo.DUMP - Dump of interger array:
317 [main] INFO  org.log4j.examples.SortAlgo.DUMP - Element [0] = 0
331 [main] INFO  org.log4j.examples.SortAlgo.DUMP - Element [1] = 1
343 [main] INFO  org.log4j.examples.Sort - The next log statement should be an error message.
346 [main] ERROR org.log4j.examples.SortAlgo.DUMP - Tried to dump an uninitialized array.
at org.log4j.examples.SortAlgo.dump(SortAlgo.java:58)
at org.log4j.examples.Sort.main(Sort.java:64)
467 [main] INFO  org.log4j.examples.Sort - Exiting main method.

The first field is the number of milliseconds elapsed since the start of the program. The second field is the thread outputting the log statement. The third field is the priority, the fourth field is the category to which the statement belongs.

The fifth field (just before the '-') is the nested diagnostic context. Note the nested diagnostic context may be empty as in the first two statements. The text after the '-' is the message of the statement.

WARNING Do not use the same TTCCLayout instance from within different appenders. The TTCCLayout is not thread safe when used in his way. However, it is perfectly safe to use a TTCCLayout instance from just one appender.

PatternLayout offers a much more flexible alternative.

Author:
Ceki Gülcü, Heinz Richter

Field Summary
protected  StringBuffer buf
           
static String CATEGORY_PREFIXING_OPTION
           
static String CONTEXT_PRINTING_OPTION
           
static String THREAD_PRINTING_OPTION
           
 
Fields inherited from class org.log4j.helpers.DateLayout
date, DATE_FORMAT_OPTION, dateFormat, NULL_DATE_FORMAT, pos, RELATIVE_TIME_DATE_FORMAT, TIMEZONE_OPTION
 
Fields inherited from class org.log4j.Layout
LINE_SEP, LINE_SEP_LEN
 
Constructor Summary
TTCCLayout()
          Instantiate a TTCCLayout object with RelativeTimeDateFormat as the date formatter in the local time zone.
TTCCLayout(String dateFormatType)
          Instantiate a TTCCLayout object using the local time zone.
 
Method Summary
 String format(LoggingEvent event)
          In addition to the priority of the statement and message, the returned byte array includes time, thread, category and NDC information.
 String[] getOptionStrings()
          Return list of strings that the OptionHandler instance recognizes.
 boolean ignoresThrowable()
          The TTCCLayout does not handle the throwable contained within LoggingEvents.
 void setCategoryPrefixing(boolean categoryPrefixing)
          Provides an alternate mehtod to setting the CategoryPrefixing option.
 void setOption(String key, String value)
          On top of the DateLayout options TTCCLayout specific options are:
 void setThreadPrinting(boolean threadPrinting)
          Provides an alternate mehtod to setting the ThreadPrinting option.
 
Methods inherited from class org.log4j.helpers.DateLayout
activateOptions, dateFormat, setDateFormat, setDateFormat, setDateFormat
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

THREAD_PRINTING_OPTION

public static final String THREAD_PRINTING_OPTION

CATEGORY_PREFIXING_OPTION

public static final String CATEGORY_PREFIXING_OPTION

CONTEXT_PRINTING_OPTION

public static final String CONTEXT_PRINTING_OPTION

buf

protected final StringBuffer buf
Constructor Detail

TTCCLayout

public TTCCLayout()
Instantiate a TTCCLayout object with RelativeTimeDateFormat as the date formatter in the local time zone.
Since:
0.7.5

TTCCLayout

public TTCCLayout(String dateFormatType)
Instantiate a TTCCLayout object using the local time zone. The DateFormat used will depend on the dateFormatType.

This constructor just calls the DateLayout.setDateFormat(java.text.DateFormat, java.util.TimeZone) method.

Method Detail

format

public String format(LoggingEvent event)
In addition to the priority of the statement and message, the returned byte array includes time, thread, category and NDC information.

Time, thread, category and diagnostic context are printed depending on options.

Overrides:
format in class Layout
Parameters:
category -  
priority -  
message -  

getOptionStrings

public String[] getOptionStrings()
Description copied from interface: OptionHandler
Return list of strings that the OptionHandler instance recognizes.
Overrides:
getOptionStrings in class DateLayout

ignoresThrowable

public boolean ignoresThrowable()
The TTCCLayout does not handle the throwable contained within LoggingEvents. Thus, it returns true.
Overrides:
ignoresThrowable in class Layout
Since:
version 0.8.4

setOption

public void setOption(String key,
                      String value)

On top of the DateLayout options TTCCLayout specific options are:

ThreadPrinting
If set to true, the printed message will include the name of the current thread. Is set to true by default.

ContextPrinting
If set to true, the printed message will include the nested context belonging to current thread. Is set to true by default.

CategoryPrefixing
If set to true, the printed message will include the category of the satetement as prefix. Is set to true by default.
Overrides:
setOption in class DateLayout

setCategoryPrefixing

public void setCategoryPrefixing(boolean categoryPrefixing)
Provides an alternate mehtod to setting the CategoryPrefixing option. Preferred method to set options is through a configuration file.

See also PropertyConfigurator.


setThreadPrinting

public void setThreadPrinting(boolean threadPrinting)
Provides an alternate mehtod to setting the ThreadPrinting option. Preferred method to set options is through the configuration file.

Seel also PropertyConfigurator


Log4j 0.9.1

Please notify me about new log4j releases.