%a - 远程ip地址,注意不一定是原始ip地址,中间可能经过nginx等的转发 %A - 本地ip %b - 发送的字节数,不包括HTTP标头,或者如果没有字节发送则使用’ - ‘ %B - 发送的字节数,不包括HTTP标头 %h - 远程主机名(或IP地址,如果连接器的enableLookups为false) %H - 请求协议 %l - Remote logical username from identd (always returns ‘-‘) %m - 请求方法(GET,POST) %p - 接受请求的本地端口 %q - 查询字符串(如果存在则用’?’作为前缀,否则为空字符串) %r - HTTP请求的第一行(包括请求方法,请求的URI) %s - HTTP的响应代码,如:200,404 %S - User session ID %t - 日期和时间,Common Log Format格式 %u - 被认证的远程用户 %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 - 当前请求的线程名,可以和打印的log对比查找问题
Access log 也支持将cookie、header、session或者其他在ServletRequest中的对象信息打印到日志中,其配置遵循Apache配置的格式({xxx}指值的名称): %{xxx}i for incoming headers,request header信息 %{xxx}o for outgoing response headers,response header信息 %{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 (see Configuration Reference document for details on supported time patterns)
/** * The type Tomcat customizer. */ @Configuration publicclassTomcatCustomizer {
/** * Configurable servlet web server factory configurable servlet web server factory. * * @return the configurable servlet web server factory */ @Bean public ConfigurableServletWebServerFactory configurableServletWebServerFactory() { TomcatServletWebServerFactoryfactory=newTomcatServletWebServerFactory(); factory.addEngineValves(getLogAccessLogValue()); return factory; }