Tomcat升级导致AccessLog名称错误

1. 问题描述

Tomcat配置

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

Tomcat7

access.2018-01-01.log
access.2018-01-02.log
access.2018-01-03.log
...

Tomcat8

access..2018-01-01.log
access..2018-01-02.log
access..2018-01-03.log
...

问题描述: Tomcat8输出的access.log文件名多了一个 .,导致读取日志文件出错

2. 原因分析

Tomcat7和Tomcat8对AccessLogValve的处理中, 对 prefix(文件前缀) 处理不同

Tomcat7 Tomcat8

Tomcat7: The Access Log Valve supports the following configuration attributes:

Attribute Description
prefix The prefix added to the start of each log file's name. If not specified, the default value is "access_log.".
suffix The suffix added to the end of each log file's name. If not specified, the default value is "" (a zero-length string), meaning that no suffix will be added.
... -

Tomcat8: The Access Log Valve supports the following configuration attributes:

Attribute Description
prefix The prefix added to the start of each log file's name. If not specified, the default value is "access_log".
suffix The suffix added to the end of each log file's name. If not specified, the default value is "" (a zero-length string), meaning that no suffix will be added.
... -

3. 解决方案

Tomcat7配置

prefix="access."

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

Tomcat8配置

prefix="access"

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

results matching ""

    No results matching ""