1、先下载logback,可以在官网地址下载:
http://logback.qos.ch/download.html
2、解压后,将logback-access.jar与logback-core.jar复制到$TOMCAT_HOME/lib/目录下
修改$TOMCAT_HOME/conf/server.xml添加:
1
|
<ValveclassName="ch.qos.logback.access.tomcat.LogbackValve"/>
|
必须添加在<Engine>或<Host>结点下。
3、logback默认会在$TOMCAT_HOME/conf下查找文件 logback-access.xml
新建 logback-access.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
<configuration>
<!-- always a good activate OnConsoleStatusListener -->
<statusListenerclass="ch.qos.logback.core.status.OnConsoleStatusListener"/>
<appendername="FILE"class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>access.log</file>
<rollingPolicyclass="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>access.%d{yyyy-MM-dd}.log.zip</fileNamePattern>
</rollingPolicy>
<encoder>
<pattern>combined</pattern>
</encoder>
</appender>
<appender-refref="FILE"/>
</configuration>
|
OK,重启tomcat即可。
来源:oschina
链接:https://my.oschina.net/u/1433107/blog/544561