我的系统是JSP+JavaBean,如何将JavaBean里面的异常信息写到日志文件里面?
try{
.....
}
cacth(Exception e){
doLog(e);
throw e;
}
private void doLog(Exception e){
try{
String logFilePath="./log/";
PrintWriter log = new PrintWriter( new FileWriter(logFilePath+"log.txt",true),true);
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss ");
log.println( formatter.format(new Date()) + e.toString() );
log.close();
}catch(Exception ee){
System.out.println(ee.toString());
}
}
推荐log4j,简单易用。
有实现的东西何必自己写呢?!