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项的值如下图所示:

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

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

virgo-tomcat访问日志的详细配置的更多相关文章

  1. Tomcat访问日志详细配置

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

  2. Tomcat访问日志详细配置(转)

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

  3. 转 Tomcat访问日志详细配置

    配置http访问日志.Tomcat自带的能够记录的http访问日志已经很详细了取消下面这段的注释: <Valve className="org.apache.catalina.valv ...

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

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

  5. Tomcat访问日志浅析 (转)

    来自:http://blog.chinaunix.net/uid-20691565-id-3938220.html Tomcat的访问日志是靠org.apache.catalina.valves.Ac ...

  6. tomcat访问日志分析

    常使用web服务器的朋友大都了解,一般的web server有两部分日志: 一是运行中的日志,它主要记录运行的一些信息,尤其是一些异常错误日志信息 二是访问日志信息,它记录的访问的时间,IP,访问的资 ...

  7. ELK之收集tomcat访问日志

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

  8. 通过Nginx,Tomcat访问日志(access log)记录请求耗时

    一.Nginx通过$upstream_response_time $request_time统计请求和后台服务响应时间 nginx.conf使用配置方式: log_format main '$remo ...

  9. ELK收集tomcat访问日志并存取mysql数据库案例

    这个案例中,tomcat产生的日志由filebeat收集,然后存取到redis中,再由logstash进行过滤清洗等操作,最后由elasticsearch存储索引并由kibana进行展示. 1.配置t ...

随机推荐

  1. Spring下获取项目根路径--good

    Spring 在 org.springframework.web.util 包中提供了几个特殊用途的 Servlet 监听器,正确地使用它们可以完成一些特定需求的功能.比如某些第三方工具支持通过 ${ ...

  2. Js加密与解密

    <html><head><META HTTP-EQUIV="MSThemeCompatible" CONTENT="Yes"> ...

  3. thinkphp 前台测试

    配置文件 <?php return array( 'DB_TYPE' => 'mysql', // 数据库类型 'DB_HOST' => 'localhost', // 服务器地址 ...

  4. C# 在Bitmap上绘制文字出现锯齿的问题

    解决锯齿问题主要是修改Graphics的属性 修复绘制图片锯齿问题可以修改 g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiA ...

  5. C++ Primer学习笔记(三) C++中函数是一种类型!!!

    C++中函数是一种类型!C++中函数是一种类型!C++中函数是一种类型! 函数名就是变量!函数名就是变量!函数名就是变量! (---20160618最新消息,函数名不是变量名...囧) (---201 ...

  6. 科技发烧友之单反佳能700d中高端

    http://detail.zol.com.cn/series/15/15795_1.html 前三 佳能 尼康 索尼 佳能5d 1.6w 佳能70d 5k 佳能6d 9k 佳能d7100 5k 尼康 ...

  7. 转载:Create a Flash Login System Using PHP and MySQL

    本文共两部分: 1. http://dev.tutsplus.com/tutorials/create-a-flash-login-system-using-php-and-mysql-part-1- ...

  8. 如何用ChemDraw建立多中心结构

    通过调整ChemDraw多中心机构的连接可绘制有意义的络合物结构,建立中心原子和络合配体后,利用多中心化学键连接上述结构即可.以下内容将具体介绍如何用ChemDraw建立多中心结构. 一.多中心键和多 ...

  9. POJ 1180 Batch Scheduling

    BTW: 刚在图书馆借了本算法艺术与信息学竞赛. 我多次有买这本书的冲动, 但每次在试看之后就放弃了, 倒不是因为书太难, 而是写的实在是太差. 大家对这本书的评价很高, 我觉得多是因为书的内容, 而 ...

  10. 【RF库Collections测试】Get From Dictionary

    Name:Get From DictionarySource:Collections <test library>Arguments:[ dictionary | key ]Returns ...