• spring boot Tomcat访问日志


    1.Tomcat设置访问日志

     1 <Host name="localhost"  appBase="webapps"
     2             unpackWARs="true" autoDeploy="true">
     3         <!--
     4         <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
     5                prefix="localhost_access_log." suffix=".txt"
     6                pattern="%h %l %u %t &quot;%r&quot; %s %b" />
     7         -->
     8         <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
     9                prefix="localhost_access_log." suffix=".txt"
    10                pattern="%h,%l,%u,%t,%T,&quot;%r&quot;,%s,%b,%{Referer}i,&quot;%{User-Agent}i&quot;,%{X-Requested-With}i" 
    11                fileDateFormat="yyyy-MM-dd.HH"
    12                />
    13 
    14       </Host>

    2.springboot设置访问日志,在properties配置文件中添加tomcat日志配置

     1 #内嵌tomcat日志
     2 server.tomcat.accesslog.buffered=true
     3 server.tomcat.accesslog.directory=/usr/microStorage/tomcatLog
     4 server.tomcat.accesslog.enabled=true
     5 #每天保存一个
     6 server.tomcat.accesslog.file-date-format=yyyy-MM-dd
     7 server.tomcat.accesslog.pattern=%h %l %T %t %r %s %b %{Referer}i %{User-Agent}i
     8 server.tomcat.accesslog.prefix=access_log
     9 server.tomcat.accesslog.rename-on-rotate=false
    10 server.tomcat.accesslog.request-attributes-enabled=false
    11 server.tomcat.accesslog.rotate=true
    12 server.tomcat.accesslog.suffix=.log

    3.日志分析,通过正在表达式,将需要分析的信息进行正则捕获提取,然后根据需要进行相关数据的统计及可视化展示

     1 public static void parse() throws Exception{
     2         String path = "D:/logs/localhost_access_log.2018-09-30.11.txt";
     3         BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(path)));
     4         String line = null;
     5         String reg = "^(.+?),(.+?),(.+?),(.+?),(.+?),(\".+?\"),(.+?),(.+?),(.+?),(\".+?\"),(.+?),(.+?)$";
     6         Pattern pattern = Pattern.compile(reg);
     7         while((line=br.readLine())!=null) {
     8             System.out.println(line);
     9             Matcher matcher = pattern.matcher(line);
    10             matcher.matches();
    11             // pattern="%h,%l,%u,%t,%T,&quot;%r&quot;,%s,%b,%{Referer}i,&quot;%{User-Agent}i&quot;,%{X-Requested-With}i,%{passport}c" 
    12             System.out.println("ip="+matcher.group(1));
    13             System.out.println("date="+matcher.group(4));
    14             System.out.println("cost="+matcher.group(5));
    15             System.out.println("request="+matcher.group(6));
    16             System.out.println("status="+matcher.group(7));
    17             System.out.println("bytes="+matcher.group(8));
    18             System.out.println("Referer="+matcher.group(9));
    19             System.out.println("User-Agent="+matcher.group(10));
    20             System.out.println("X-Requested-With="+matcher.group(11));
    21             System.out.println("passport="+matcher.group(12));
    22             System.out.println("------------------------------------");
    23         }
    24         br.close();
    25     }
  • 相关阅读:
    Codeforces Round #248 (Div. 2) C. Ryouko's Memory Note
    Codeforces Round #103 (Div. 2) D. Missile Silos(spfa + 枚举边)
    Codeforces Round #174 (Div. 1) B. Cow Program(dp + 记忆化)
    Linux安装redis数据库及添加环境变量
    window安装redis数据库
    Python时间获取详解,Django获取时间详解,模板中获取时间详解(navie时间和aware时间)
    解决跨域HttpResponseJsonCORS, HttpResponseCORS 返回字典数据
    python通过原生sql查询数据库(共享类库)
    元组套元组转列表套字典数据格式
    django自带过滤器大全
  • 原文地址:https://www.cnblogs.com/wang-yaz/p/10030357.html
Copyright © 2020-2023  润新知