首页 技术 正文
技术 2022年11月8日
0 收藏 593 点赞 2,120 浏览 2389 个字

Tomcat 日志信息分为两类:
1、运行中的日志,它主要记录运行的一些信息,尤其是一些异常错误日志信息。
2、访问日志信息,它记录的访问的时间、IP、访问的资料等相关信息。

关于tomcat访问日志的产生样式说明如下(从官方文档中摘录):

%a - Remote IP address
%A - Local IP address
%b - Bytes sent, excluding HTTP headers, or '-' if zero
%B - Bytes sent, excluding HTTP headers
%h - Remote host name (or IP address if enableLookups for the connector is false)
%H - Request protocol
%l - Remote logical username from identd (always returns '-')
%m - Request method (GET, POST, etc.)
%p - Local port on which this request was received
%q - Query string (prepended with a '?' if it exists)
%r - First line of the request (method and request URI)
%s - HTTP status code of the response
%S - User session ID
%t - Date and time, in Common Log Format
%u - Remote user that was authenticated (if any), else '-'
%U - Requested URL path
%v - Local server name
%D - Time taken to process the request, in millis
%T - Time taken to process the request, in seconds
%F - Time taken to commit the response, in millis
%I - Current request thread name (can compare later with stacktraces)

There is also support to write information incoming or outgoing headers, cookies, session or request attributes and special timestamp formats. It is modeled after the Apache HTTP Server log configuration syntax:

%{xxx}i for incoming headers
%{xxx}o for outgoing response headers
%{xxx}c for a specific cookie
%{xxx}r xxx is an attribute in the ServletRequest
%{xxx}s xxx is an attribute in the HttpSession
%{xxx}t xxx is an enhanced SimpleDateFormat pattern

上面最后一段的内容大概意思是我们还可以将cookie, 客户端请求中带的HTTP头(incoming header), 会话(session)或是ServletRequest中的数据都写到Tomcat的访问日志中

我们可以用下面的语法来引用。

%{xxx}i      –      记录客户端请求中带的HTTP头xxx(incoming headers)
%{xxx}c – 记录特定的cookie xxx
%{xxx}r – 记录ServletRequest中的xxx属性(attribute)
%{xxx}s – 记录HttpSession中的xxx属性(attribute)

对于日志项值还可以可以为:common与combined,这两个预先设置好的格式对应的日志输出内容如下:
common   的值: %h %l %u %t %r %s %b
combined 的值: %h %l %u %t %r %s %b %{Referer}i %{User-Agent}i

但本人建议采用以下具体的配置,因为标准配置有一些重要的日志数据无法生。

%{Host}i                 是用于发送的 HTTP请求中的 Host这个字段的值。
%h                           访问的用户主机名(if resolveHosts is false,就显示IP地址)
%B                           访问资源返回的流量,单位为Byte,即字节
%T                           访问所使用的时间,同一资源、每次访问的时间不一定相同。
%t                            时间字段,默认的时间格式为[13/Jun/2014:13:41:52 +0800]
%s                            访问返回的http状态码
%r                            访问的方式(post或者是get),访问的URI和使用的http协议版本(返回3列值)
%{User-Agent}i       用户的User-Agent信息

如本人使用的是virgo-tomcat-server(集成版本的tomcat)服务器,我们可以修改virgo-tomcat-server-3.6.0.RELEASE/configuration/tomcat-server.xml配置文件,配置pattern项的值如下图所示:

virgo-tomcat访问日志的详细配置

对于%t我们可以使用%{yyyy-MM-dd HH:mm:ss}t作格化时间显示调整。可方便我们更好的阅读、个人建议可以将格式化的值用中括号[]括起来。

有了这些数据,我们可以根据时间段做以下的分析处理(图片使用jfreechart工具动态生成):
* 访问请求数、独立IP数统计
* 访问资料文件数统计以及访问流量统计
* 访问处理响应时间统计
* 统计所有404与500错误页面
* 统计访问最频繁页面
* 统计访问处理时间最久页面
* 统计并发访问频率最高的页面

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,962
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,486
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,331
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,114
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,747
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,781