自己做的一个简易日志系统,欢迎提出意见
[code=Java]public class MyLog {
private final String defaultPath = "log ";//默认日志存放目录
private final long length = 3 * 1024 * 1024;//单个日志文件大小
private static MyLog instance = null;
private String path;//日志存放目录
private Class clazz;
private boolean flag;//启动日志开关
private File file;
private MyLog() {
createFile();
setFlag(true);
}
public static MyLog getInstance(Class clazz) {
if (instance == null) {
instance = new MyLog();
}
instance.setClazz(clazz);
return instance;
}
public void writeLog(Object obj) {
if (flag) {
try {
FileWriter fw = new FileWriter(file, true);
PrintWriter pw = new PrintWriter(fw);
pw.println(currentTime() + "\t\tclass( " + getClazz().getName() + ") ");
pw.println(obj);
pw.println();
pw.close();
fw.close();
} catch (
IOException e) {
e.printStackTrace();
}
}
}
public void writeLog(String methodName, Object obj) {
if (flag) {