• 日志,获取logback日志文件路径,


            response.setContentType("application/octet-stream");
            response.setHeader("Content-Disposition", "attachment;filename="+new String((System.currentTimeMillis()+".log").getBytes("utf-8"),"ISO-8859-1"));
            OutputStream out = response.getOutputStream();
            LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
            String fileStr = ((RollingFileAppender) loggerContext.getLogger("ROOT").getAppender("FILE")).getFile();
            File file = new File(fileStr);
            BufferedReader br = new BufferedReader(new FileReader(file));
            String time = map.get("time");
            StringUtils.isEmptyReMsg(time,"XXX");
            int i=0;
            String line="";
            while (i<3000&&(line=br.readLine())!=null){
                i++;
                DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
                if(line.length()>25){
                    try{
                        LocalDateTime parse = LocalDateTime.parse(line.substring(1,24), df);
                        LocalDateTime parse2 = LocalDateTime.parse(time, df);
                        if(parse.compareTo(parse2)<0){
                            break;
                        }
                    }catch (Exception e){
                    }
                }
                out.write((line+System.getProperty("line.separator")).getBytes());
            }
            br.close();
            out.flush();
            out.close();

     

  • 相关阅读:
    通信原理
    java实现聊天室的简单实现
    计算机网络笔记——第四章、网络层
    泛型高级之通配符
    看文档总结
    HashSet源码解析
    HashTable源码解析
    计算机网络笔记——第三章、数据链路层
    Collection集合的功能
    第六章 应用层
  • 原文地址:https://www.cnblogs.com/qq376324789/p/16160506.html
Copyright © 2020-2023  润新知