首页 > 其他分享 >AccessLog日志配置

AccessLog日志配置

时间:2022-11-08 14:56:46浏览次数:57  
标签:AccessLog xxx name tomcat -- 配置 request write 日志

  • server.tomcat.accesslog.prefix = access
    server.tomcat.accesslog.suffix = .log
    server.tomcat.accesslog.file-date-format = -yyyyMMddHH

     

    有的时候我们要使用日志分析工具对日志进行分析,需要对日志进行格式化,比如,要把accessLog格式化成这样的格式

    c-ip s-ip x-InstancePort date time-taken x-Protocol cs-method cs-uri sc-status x-ResponseSize bytes x-Referrer x-UserAgent

    在tomcat的conf/server.xml加入配置:

    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
                   prefix="localhost_access_log" suffix=".txt"
                   pattern="%{X-Real-IP}i %A %p %{yyyy-MM-dd HH:mm:ss}t %D %H %m %U %s %B %B %{Referer}i %{User-Agent}i" />

    关于accessLog的官方说明,请看 http://tomcat.apache.org/tomcat-8.0-doc/config/valve.html#Access_Logging 

    常用配置如下:

    • %a - Remote IP address  --远程IP地址
    • %A - Local IP address --本地IP地址
    • %b - Bytes sent, excluding HTTP headers, or '-' if zero --发送的字节数(Bytes sent), 不包括HTTP headers的字节,如果为0则展示'-'
    • %B - Bytes sent, excluding HTTP headers --发送的字节数(Bytes sent), 不包括HTTP headers的字节
    • %h - Remote host name (or IP address if enableLookups for the connector is false) --远程主机名称(如果resolveHosts为false则展示IP)
    • %H - Request protocol --请求协议
    • %l - Remote logical username from identd (always returns '-') --远程用户名,始终为'-'(Remote logical username from identd)
    • %m - Request method (GET, POST, etc.) --请求的方法(GET, POST等)
    • %p - Local port on which this request was received. See also %{xxx}p below. --接受请求的本地端口
    • %q - Query string (prepended with a '?' if it exists) --查询字符串,如果存在,有一个前置的'?'
    • %r - First line of the request (method and request URI) --请求的第一行(包括请求方法和请求的URI)
    • %s - HTTP status code of the response --response的HTTP状态码(200,404等)
    • %S - User session ID --用户的session ID
    • %t - Date and time, in Common Log Format --日期和时间,Common Log Format格式
    • %u - Remote user that was authenticated (if any), else '-' --被认证的远程用户, 不存在则展示'-'
    • %U - Requested URL path --请求URL路径
    • %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) --当前请求的线程名

    Access Log中也支持cookie,请求header,响应headers,Session或者其他在ServletRequest中的对象的信息

    • %{xxx}i write value of incoming header with name xxx
    • %{xxx}o write value of outgoing header with name xxx
    • %{xxx}c write value of cookie with name xxx
    • %{xxx}r write value of ServletRequest attribute with name xxx
    • %{xxx}s write value of HttpSession attribute with name xxx
    • %{xxx}p write local (server) port (xxx==local) or remote (client) port (xxx=remote)
    • %{xxx}t write timestamp at the end of the request formatted using the enhanced SimpleDateFormat pattern xxx

    如果tomcat前面有nginx做负载均衡,则要修改nginx的配置

    Nginx的server主机配置段中添加:

    proxy_set_header X-Real-IP $remote_addr; #真实的远端IP地址

    so  再tomcat accessLog用%{X-Real-IP}i 获取即可

  •  

标签:AccessLog,xxx,name,tomcat,--,配置,request,write,日志
From: https://www.cnblogs.com/yanlai/p/16869699.html

相关文章

  • php配置
    vimphp-fpm.conf[global]pid=/www/server/php/72/var/run/php-fpm.piderror_log=/www/server/php/72/var/log/php-fpm.loglog_level=notice[www]listen=/tmp/php......
  • Pycharm配置
    平台:win10x64Pycharm的下载,安装,,编辑字体+配置IDE 博客中问题——远程连接编程问题:问题描述:在XShell上查看虚拟机IP地址——输入ipconfig命令查看ip,结果提示ipconfig:com......
  • 华为防火墙配置命令大全,超级详细
    https://blog.csdn.net/qfliweimin/article/details/124932875防火墙(Firewall)也称防护墙,是由CheckPoint创立者GilShwed于1993年发明并引入国际互联网(US5606668(A)1993-12-......
  • Serilog + Seq 搭建日志平台
    Docker部署Seq日志平台Dokce部署镜像地址:https://hub.docker.com/r/datalust/seqpull镜像dockerpulldatalust/seq设置seqAdmin密码,起站点用到的密码必须要Hash......
  • process.env前端环境变量配置教程
    1、为什么要配置环境变量在公司,一个项目一般会有开发版本、测试版本、灰度版本和线上版本,每个版本会对应相同或不同的数据库、API地址。为了方便管理,我们通常做成配置文件的......
  • Jmeter安装+环境变量配置(Win10环境)
    一、JDK安装安装Jmeter前需要安装JDK下载网址:https://www.oracle.com/进入网页后,点击Product,选择Java。  下拉,选择OracleJDK 下拉,选择你需要的环境,这里是Win......
  • ubuntu samba 配置
    1.说明samba配置主要分为安装samba、配置samba、添加用户等步骤。2.安装sambasudoapt-getinstallsambasudoapt-getinstallsmbclient3.配置samba打开配置文件sudo......
  • 基于 Anaconda和Pycharm 开发环境配置
    1.先下载Anaconda,安装后直接有python地址 ​​https://www.anaconda.com/products/individual​​2.下载pycharm社区版,projectinterpreter中选择Anaconda中的python3.......
  • 微服务网关 APISIX 在 CentOS 7 下安装配置指南
    1.简介1.1.参考资源微服务网关的介绍和说明前面已有介绍,相关的文档可以参考以下链接。Nginx最大的问题是官方没有提供GUI方式的管理界面并且在群集方面的支持有限,所有配......
  • vc++读写配置文件
    voidcheckConfig(){char*AppName="TS37";char*ConfigFile="./config.ini";char*ItemName="StationNum";char*defValue="0";constintbufSize=10......