in log4j-1.2-api/src/main/java/org/apache/log4j/helpers/PatternParser.java [213:325]
protected void finalizeConverter(char c) {
PatternConverter pc = null;
switch (c) {
case 'c':
pc = new CategoryPatternConverter(formattingInfo, extractPrecisionOption());
// LogLog.debug("CATEGORY converter.");
// formattingInfo.dump();
currentLiteral.setLength(0);
break;
case 'C':
pc = new ClassNamePatternConverter(formattingInfo, extractPrecisionOption());
// LogLog.debug("CLASS_NAME converter.");
// formattingInfo.dump();
currentLiteral.setLength(0);
break;
case 'd':
String dateFormatStr = AbsoluteTimeDateFormat.ISO8601_DATE_FORMAT;
DateFormat df;
final String dOpt = extractOption();
if (dOpt != null) dateFormatStr = dOpt;
if (dateFormatStr.equalsIgnoreCase(AbsoluteTimeDateFormat.ISO8601_DATE_FORMAT))
df = new ISO8601DateFormat();
else if (dateFormatStr.equalsIgnoreCase(AbsoluteTimeDateFormat.ABS_TIME_DATE_FORMAT))
df = new AbsoluteTimeDateFormat();
else if (dateFormatStr.equalsIgnoreCase(AbsoluteTimeDateFormat.DATE_AND_TIME_DATE_FORMAT))
df = new DateTimeDateFormat();
else {
try {
df = new SimpleDateFormat(dateFormatStr);
} catch (IllegalArgumentException e) {
LogLog.error("Could not instantiate SimpleDateFormat with " + dateFormatStr, e);
df = (DateFormat) OptionConverter.instantiateByClassName(
"org.apache.log4j.helpers.ISO8601DateFormat", DateFormat.class, null);
}
}
pc = new DatePatternConverter(formattingInfo, df);
// LogLog.debug("DATE converter {"+dateFormatStr+"}.");
// formattingInfo.dump();
currentLiteral.setLength(0);
break;
case 'F':
pc = new LocationPatternConverter(formattingInfo, FILE_LOCATION_CONVERTER);
// LogLog.debug("File name converter.");
// formattingInfo.dump();
currentLiteral.setLength(0);
break;
case 'l':
pc = new LocationPatternConverter(formattingInfo, FULL_LOCATION_CONVERTER);
// LogLog.debug("Location converter.");
// formattingInfo.dump();
currentLiteral.setLength(0);
break;
case 'L':
pc = new LocationPatternConverter(formattingInfo, LINE_LOCATION_CONVERTER);
// LogLog.debug("LINE NUMBER converter.");
// formattingInfo.dump();
currentLiteral.setLength(0);
break;
case 'm':
pc = new BasicPatternConverter(formattingInfo, MESSAGE_CONVERTER);
// LogLog.debug("MESSAGE converter.");
// formattingInfo.dump();
currentLiteral.setLength(0);
break;
case 'M':
pc = new LocationPatternConverter(formattingInfo, METHOD_LOCATION_CONVERTER);
// LogLog.debug("METHOD converter.");
// formattingInfo.dump();
currentLiteral.setLength(0);
break;
case 'p':
pc = new BasicPatternConverter(formattingInfo, LEVEL_CONVERTER);
// LogLog.debug("LEVEL converter.");
// formattingInfo.dump();
currentLiteral.setLength(0);
break;
case 'r':
pc = new BasicPatternConverter(formattingInfo, RELATIVE_TIME_CONVERTER);
// LogLog.debug("RELATIVE time converter.");
// formattingInfo.dump();
currentLiteral.setLength(0);
break;
case 't':
pc = new BasicPatternConverter(formattingInfo, THREAD_CONVERTER);
// LogLog.debug("THREAD converter.");
// formattingInfo.dump();
currentLiteral.setLength(0);
break;
/*
* case 'u': if(i < patternLength) { char cNext = pattern.charAt(i); if(cNext >= '0' && cNext <= '9') { pc = new
* UserFieldPatternConverter(formattingInfo, cNext - '0'); LogLog.debug("USER converter ["+cNext+"].");
* formattingInfo.dump(); currentLiteral.setLength(0); i++; } else LogLog.error("Unexpected char"
* +cNext+" at position "+i); } break;
*/
case 'x':
pc = new BasicPatternConverter(formattingInfo, NDC_CONVERTER);
// LogLog.debug("NDC converter.");
currentLiteral.setLength(0);
break;
case 'X':
final String xOpt = extractOption();
pc = new MDCPatternConverter(formattingInfo, xOpt);
currentLiteral.setLength(0);
break;
default:
LogLog.error("Unexpected char [" + c + "] at position " + i + " in conversion pattern.");
pc = new LiteralPatternConverter(currentLiteral.toString());
currentLiteral.setLength(0);
}
addConverter(pc);
}