1.Tomcat设置访问日志

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

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

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

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

 public static void parse() throws Exception{
String path = "D:/logs/localhost_access_log.2018-09-30.11.txt";
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(path)));
String line = null;
String reg = "^(.+?),(.+?),(.+?),(.+?),(.+?),(\\\".+?\\\"),(.+?),(.+?),(.+?),(\\\".+?\\\"),(.+?),(.+?)$";
Pattern pattern = Pattern.compile(reg);
while((line=br.readLine())!=null) {
System.out.println(line);
Matcher matcher = pattern.matcher(line);
matcher.matches();
// pattern="%h,%l,%u,%t,%T,&quot;%r&quot;,%s,%b,%{Referer}i,&quot;%{User-Agent}i&quot;,%{X-Requested-With}i,%{passport}c"
System.out.println("ip="+matcher.group(1));
System.out.println("date="+matcher.group(4));
System.out.println("cost="+matcher.group(5));
System.out.println("request="+matcher.group(6));
System.out.println("status="+matcher.group(7));
System.out.println("bytes="+matcher.group(8));
System.out.println("Referer="+matcher.group(9));
System.out.println("User-Agent="+matcher.group(10));
System.out.println("X-Requested-With="+matcher.group(11));
System.out.println("passport="+matcher.group(12));
System.out.println("------------------------------------");
}
br.close();
}

spring boot Tomcat访问日志的更多相关文章

  1. 如何配置Spring Boot Tomcat

    1.概述 Spring Boot Web应用程序默认包含预配置的嵌入式Web服务器.但在某些情况下,我们要修改默认配置以满足自定义要求. 在本教程中,我们将介绍通过application.proper ...

  2. Spring Boot 系列:日志动态配置详解

    世界上最快的捷径,就是脚踏实地,本文已收录架构技术专栏关注这个喜欢分享的地方. 开源项目: 分布式监控(Gitee GVP最有价值开源项目 ):https://gitee.com/sanjianket ...

  3. 06.深入浅出 Spring Boot - 数据访问之Druid

    代码下载:https://github.com/Jackson0714/study-spring-boot.git 一.Druid是什么? 1.Druid是数据库连接池,功能.性能.扩展性方面都算不错 ...

  4. Tomcat访问日志详细配置

    在server.xml里的<host>标签下加上 <Valve className="org.apache.catalina.valves.AccessLogValve&q ...

  5. Spring Boot Logback应用日志

    e Spring Boot Logback应用日志 2015-09-08 19:57 7673人阅读 评论(0) 收藏 举报 . 分类: Spring Boot(51) . 目录(?)[+] 日志对于 ...

  6. linux系统tomcat项目部署和tomcat访问日志

    一.只用ip地址访问 先把端口号改成80,然后用 <Host name="localhost"  appBase="webapps"    137     ...

  7. Spring Boot入门教程2-1、使用Spring Boot+MyBatis访问数据库(CURD)注解版

    一.前言 什么是MyBatis?MyBatis是目前Java平台最为流行的ORM框架https://baike.baidu.com/item/MyBatis/2824918 本篇开发环境1.操作系统: ...

  8. spring boot整合slf4j-log日志

    原文地址:https://blog.csdn.net/u011271894/article/details/75735915 版权声明:本文为博主原创文章,未经博主允许不得转载. https://bl ...

  9. ELK之收集tomcat访问日志

    把tomcat访问日志转换成json格式然后收集 修改配置文件conf/server.xml把日志输出改成json格式 添加logstash配置文件(日志按天切割可以使用*进行匹配所有)

随机推荐

  1. python colorama模块

    colorama是一个python专门用来在控制台.命令行输出彩色文字的模块,可以跨平台使用. 1. 安装colorama模块 pip install colorama 可用格式常数: Fore: B ...

  2. 传统OGG与Microservice Architecture OGG的通信

    针对当前新出的ogg microservice architect(MA),现在只支持oracle 11g/12c的数据复制和投递.如果有其它版本的oracle或其它数据库,比如 mysql, db2 ...

  3. kivy Properties

    Introduction to Properties¶ Properties are an awesome way to define events and bind to them. Essenti ...

  4. HTML <​canvas> testing with Selenium and OpenCV

    from: https://www.linkedin.com/pulse/html-canvas-testing-selenium-opencv-maciej-kusz Since HTML < ...

  5. centos6二进制安装mysql5.5

    centos 6.5,安装mysql 5.5.60 所需安装包mysql-5.5.60-linux-glibc2.12-x86_64.tar.gz.ncurses-devel-5.7-4.200902 ...

  6. fjwc2019 D1T2 原样输出(后缀自动机+dp)

    #179. 「2019冬令营提高组」原样输出 暴力对每个串建后缀自动机,然后暴力枚举每个自动机的子串.可以拿到部分分. 然鹅我们可以把每个后缀自动机连起来. 我们知道,后缀自动机是用最少的点(空间)表 ...

  7. bzoj4720 / P1850 换教室(Floyd+期望dp)

    P1850 换教室 先用Floyd把最短路处理一遍,接下来就是重头戏了 用 f [ i ][ j ][ 0/1 ] 表示在第 i 个时间段,发出了 j 次申请(注意不一定成功),并且在这个时间段是否( ...

  8. DevExpress GridControl使用方法总结2

    一.如何解决单击记录整行选中的问题 View->OptionsBehavior->EditorShowMode 设置为:Click 二.如何新增一条记录 (1).gridView.AddN ...

  9. 【题解】Luogu P3950 部落冲突

    原题传送门 这题用Link-Cut-Tree解决,Link-Cut-Tree详解 我们用Link-Cut-Tree维护连通性(十分无脑) 一开始先把树中每条边的两端连接 U操作:把u,v两个点连起来 ...

  10. python简说(五)操作文件

    f = open('users.txt',encoding='utf-8') #读文件的时候,必须存在在才可以读 文件对象,或者文件句柄res = f.read()print(res)f.close( ...