public class TTCCLayout extends DateLayout
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 com.fr.third.apache.log4j.examples.Sort - Populating an array of 2 elements in reverse order. 225 [main] INFO com.fr.third.apache.log4j.examples.SortAlgo - Entered the sort method. 262 [main] DEBUG com.fr.third.apache.log4j.examples.SortAlgo.OUTER i=1 - Outer loop. 276 [main] DEBUG com.fr.third.apache.log4j.examples.SortAlgo.SWAP i=1 j=0 - Swapping intArray[0] = 1 and intArray[1] = 0 290 [main] DEBUG com.fr.third.apache.log4j.examples.SortAlgo.OUTER i=0 - Outer loop. 304 [main] INFO com.fr.third.apache.log4j.examples.SortAlgo.DUMP - Dump of interger array: 317 [main] INFO com.fr.third.apache.log4j.examples.SortAlgo.DUMP - Element [0] = 0 331 [main] INFO com.fr.third.apache.log4j.examples.SortAlgo.DUMP - Element [1] = 1 343 [main] INFO com.fr.third.apache.log4j.examples.Sort - The next log statement should be an error message. 346 [main] ERROR com.fr.third.apache.log4j.examples.SortAlgo.DUMP - Tried to dump an uninitialized array. at com.fr.third.apache.log4j.examples.SortAlgo.dump(SortAlgo.java:58) at com.fr.third.apache.log4j.examples.Sort.main(Sort.java:64) 467 [main] INFO com.fr.third.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.
PatternLayout
offers a much more flexible alternative.
限定符和类型 | 字段和说明 |
---|---|
protected java.lang.StringBuffer |
buf |
date, DATE_FORMAT_OPTION, dateFormat, NULL_DATE_FORMAT, pos, RELATIVE_TIME_DATE_FORMAT, TIMEZONE_OPTION
LINE_SEP, LINE_SEP_LEN
构造器和说明 |
---|
TTCCLayout()
Instantiate a TTCCLayout object with
RelativeTimeDateFormat as the date
formatter in the local time zone. |
TTCCLayout(java.lang.String dateFormatType)
Instantiate a TTCCLayout object using the local time zone.
|
限定符和类型 | 方法和说明 |
---|---|
java.lang.String |
format(LoggingEvent event)
In addition to the level of the statement and message, the
returned byte array includes time, thread, category and
NDC
information. |
boolean |
getCategoryPrefixing()
Returns value of the CategoryPrefixing option.
|
boolean |
getContextPrinting()
Returns value of the ContextPrinting option.
|
boolean |
getThreadPrinting()
Returns value of the ThreadPrinting option.
|
boolean |
ignoresThrowable()
The TTCCLayout does not handle the throwable contained within
LoggingEvents . |
void |
setCategoryPrefixing(boolean categoryPrefixing)
The CategoryPrefixing option specifies whether
Category
name is part of log output or not. |
void |
setContextPrinting(boolean contextPrinting)
The ContextPrinting option specifies log output will include
the nested context information belonging to the current thread.
|
void |
setThreadPrinting(boolean threadPrinting)
The ThreadPrinting option specifies whether the name of the
current thread is part of log output or not.
|
activateOptions, dateFormat, getDateFormat, getOptionStrings, getTimeZone, setDateFormat, setDateFormat, setDateFormat, setOption, setTimeZone
getContentType, getFooter, getHeader
public TTCCLayout()
RelativeTimeDateFormat
as the date
formatter in the local time zone.public TTCCLayout(java.lang.String dateFormatType)
dateFormatType
.
This constructor just calls the DateLayout.setDateFormat(java.lang.String)
method.
public void setThreadPrinting(boolean threadPrinting)
public boolean getThreadPrinting()
public void setCategoryPrefixing(boolean categoryPrefixing)
Category
name is part of log output or not. This is true by default.public boolean getCategoryPrefixing()
public void setContextPrinting(boolean contextPrinting)
public boolean getContextPrinting()
public java.lang.String format(LoggingEvent event)
NDC
information.
Time, thread, category and diagnostic context are printed depending on options.
public boolean ignoresThrowable()
LoggingEvents
. Thus, it returns
true
.ignoresThrowable
在类中 Layout