您的位置:首页 > 其它

重定向输出流实现程序日志

2014-10-24 11:19 281 查看
public String delete() throws Exception{

  try {

   PrintStream out = System.out;//保存原输出流

   PrintStream ps = new PrintStream("E:/log.txt");//创建文件输出流 地址不正确则没办法存入

   System.setOut(ps);//设置使用新的输出流

   

   edocEntryService.delete(ede.getId());

   

   Date now = new Date();

   SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");//可以方便地修改日期格式

   String time = dateFormat.format( now );

   System.out.println(time);

   System.out.println("此操作删除了id为:" + ede.getId() + "的数据");

   System.setOut(out);//恢复原有输出流

   System.out.println("程序输出完毕,请查看日志文件");

   

  } catch (Exception e) {

   e.printStackTrace();

  }

  return "del";

 }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  程序日志