accesslog

简介

HTTP访问日志包含HTTP端点处理的所有入站客户端请求的记录。您可以在HTTP服务器中启用访问日志记录

tomcat-accesslog 参考路径

https://tomcat.apache.org/tomcat-8.5-doc/config/valve.html#Access_Logging

pattern

%a - Remote IP address,远程ip地址,注意不一定是原始ip地址,中间可能经过nginx等的转发
%A - Local IP address,本地ip
%b - Bytes sent, excluding HTTP headers, or '-' if no bytes were sent
%B - Bytes sent, excluding 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 '-')
%m - Request method,请求方法(GET,POST)
%p - Local port,接受请求的本地端口
%q - Query string (prepended with a '?' if it exists, otherwise an empty string
%r - First line of the request,HTTP请求的第一行(包括请求方法,请求的URI)
%s - HTTP status code of the response,HTTP的响应代码,如:200,404
%S - User session ID
%t - Date and time, in Common Log Format format,日期和时间,Common Log Format格式
%u - Remote user that was authenticated
%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,处理请求的时间,单位秒
%I - current Request thread name (can compare later with stacktraces),当前请求的线程名,可以和打印的log对比查找问题

springboot下的accesslog

yml

server:
  tomcat:
    accesslog:
       enabled: true // 默认false
       file-data-format: .yyyy-MM-dd
       direcotry: ./accesslog/
       encoding: utf-8
       max-days: 10
       pattern: "%t [%I] %{X-Forwarded-For}i %l %a %u %r %s %b %D"
       suffix: .log
       prefix: access_log

properties

server.tomcat.accesslog.enabled=true
server.tomcat.accesslog.directory=./accesslog/
server.tomcat.accesslog.encoding=UTF-8
server.tomcat.accesslog.file-date-format=.yyyy-MM-dd
server.tomcat.accesslog.max-days=10
server.tomcat.accesslog.pattern="%t [%I] %{X-Forwarded-For}i %l %a %u %r %s %b %D"
server.tomcat.accesslog.prefix=access_log
server.tomcat.accesslog.suffix=.log

tomcat下的accesslog

<Host name="localhost"  appBase="webapps"
        unpackWARs="true" autoDeploy="true">
    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" 
        prefix="access." suffix=".log" 
        pattern="%a %h %l %u %t "%r" %s %b "%{Referer}i" "%{User-Agent}i" "%{QunarGlobal}c" %{X-Forwarded-For}i"
        resolveHosts="false"/>
</Host>

nginx下的accesslog

worker_processes  1;
error_log logs/error.log error;
events {
    worker_connections  1024;
}
http {
    include status.conf;
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                               '$status $body_bytes_sent "$http_referer" '
                               '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  logs/access.log  main;
    server {
		access_log /data/log/www;
		listen 80;
		server_name abc.com www.wl.com;

		location / {
				root /data/www/www;
				index index.html index.htm;
		}
		error_log    logs/error_www.wl.com.log    error;
		access_log    logs/access_www.wl.com.log    main;
    }
    include vhost/*.conf;
}
posted @ 2020-08-11 09:25  pengsn  阅读(401)  评论(0编辑  收藏  举报