FileDocCategorySizeDatePackage
TTCCLayout.javaAPI DocApache log4j 1.2.156696Sat Aug 25 00:09:42 BST 2007org.apache.log4j

TTCCLayout

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 {@link org.apache.log4j.helpers.RelativeTimeDateFormat}.

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

{@link PatternLayout} offers a much more flexible alternative.

author
Ceki Gülcü
author
Heinz Richter

Fields Summary
private boolean
threadPrinting
private boolean
categoryPrefixing
private boolean
contextPrinting
protected final StringBuffer
buf
Constructors Summary
public TTCCLayout()
Instantiate a TTCCLayout object with {@link org.apache.log4j.helpers.RelativeTimeDateFormat} as the date formatter in the local time zone.

since
0.7.5



                                     
    
    this.setDateFormat(RELATIVE_TIME_DATE_FORMAT, null);
  
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 {@link DateLayout#setDateFormat} method.

    this.setDateFormat(dateFormatType);
  
Methods Summary
public java.lang.Stringformat(org.apache.log4j.spi.LoggingEvent event)
In addition to the level of the statement and message, the returned byte array includes time, thread, category and {@link NDC} information.

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

param
event The event to format


    // Reset buf
    buf.setLength(0);

    dateFormat(buf, event);

    if(this.threadPrinting) {
      buf.append('[");
      buf.append(event.getThreadName());
      buf.append("] ");
    }
    buf.append(event.getLevel().toString());
    buf.append(' ");

    if(this.categoryPrefixing) {
      buf.append(event.getLoggerName());
      buf.append(' ");
    }

    if(this.contextPrinting) {
       String ndc = event.getNDC();

      if(ndc != null) {
	buf.append(ndc);
	buf.append(' ");
      }
    }
    buf.append("- ");
    buf.append(event.getRenderedMessage());
    buf.append(LINE_SEP);
    return buf.toString();
  
public booleangetCategoryPrefixing()
Returns value of the CategoryPrefixing option.

    return categoryPrefixing;
  
public booleangetContextPrinting()
Returns value of the ContextPrinting option.

    return contextPrinting;
  
public booleangetThreadPrinting()
Returns value of the ThreadPrinting option.

    return threadPrinting;
  
public booleanignoresThrowable()
The TTCCLayout does not handle the throwable contained within {@link LoggingEvent LoggingEvents}. Thus, it returns true.

since
version 0.8.4

    return true;
  
public voidsetCategoryPrefixing(boolean categoryPrefixing)
The CategoryPrefixing option specifies whether {@link Category} name is part of log output or not. This is true by default.

    this.categoryPrefixing = categoryPrefixing;
  
public voidsetContextPrinting(boolean contextPrinting)
The ContextPrinting option specifies log output will include the nested context information belonging to the current thread. This is true by default.

    this.contextPrinting = contextPrinting;
  
public voidsetThreadPrinting(boolean threadPrinting)
The ThreadPrinting option specifies whether the name of the current thread is part of log output or not. This is true by default.

    this.threadPrinting = threadPrinting;