代码接第(4)章;
private void writeLogWithModule(FileWriter fw, LogConfigBean lc)
throws IOException {
String pkgName = lc.getModuleName();
String append = LOG4J_APPEND_KEY_PREFIX + pkgName;
initData(fw, LOG4J_KEY_PREFIX + pkgName, lc.getLogLevel() + COMMA
+ pkgName);
initData(fw, append, FILE_APPEND_VALUE);
initData(fw, append + FILE_KEY_PREFIX,
"${logdir}" + lc.getLogFileName());
initData(fw, append + DATE_PATTERN_KEY, DATE_PATTERN_VALUE);
initData(fw, append + ".Append", "true");
initData(fw, append + MAX_FILE_SIZE_KEY_PREFIX, lc.getLogFileSize()
+ "MB");
initData(fw, append + MAX_BACKUP_INDEX,
String.valueOf(lc.getLogMaxFileCount()));
initData(fw, append + LAYOUT_KEY_PREFIX, LAYOUT_VALUE);
initData(fw, append + LAYOUT_PATTERN_KEY, LAYOUT_PATTERN_VALUE);
}
/**
* 读取Log4j的配置信息 <功能具体描写叙述>
*
* @return Properties [返回类型说明]
* @see [类、类#方法、类#成员]
*/
private Properties readLog4jProperties() {
Properties props = readProperties(WEB_INF_PATH + LOG4J_PROPERTIES_NAME);
// 推断props是否为空
if (props.isEmpty()) {
props = new Properties();
}
// 日志路径为空则取默认路径
if (props.getProperty("logdir") == null) {
props.setProperty("logdir", LOG_PATH);
}
return props;
}