【Java开源代码栏目提醒】:网学会员鉴于大家对Java开源代码十分关注,论文会员在此为大家搜集整理了“TimeFileAppender.java”一文,供大家参考学习
package org.appfuse.util.log;
import java.io.*;
import org.apache.log4j.*;
public class TimeFileAppender
extends DailyRollingFileAppender {
public void setFile(String file) {
String FILE_SEP = System.getProperty("file.separator");
String val = file.trim();
String tmpfileName = val.replace('/', FILE_SEP.charAt(0));
if (!tmpfileName.startsWith(FILE_SEP)) {
tmpfileName = FILE_SEP + tmpfileName;
}
String rootPath = "";
java.io.File curFile = new java.io.File(".");
try {
rootPath = curFile.getCanonicalPath();
}
catch (IOException ex) {
System.err.println("Get app root path error:" +
ex.getMessage());
}
fileName = rootPath + tmpfileName;
//create non-exist path
System.out.println("the root of log file: " + rootPath);
System.out.println("the log file: " + fileName);
int index = fileName.lastIndexOf(FILE_SEP);
if (index > 0) {
String sPath = fileName.substring(0, index);
File path = new File(sPath);
if (!path.exists()) {
path.mkdirs();
}
}
}
}
上一篇:
TimeField.java
下一篇:
试论建设企业信息化提升企业竞争力