一、先下載logback,能夠在官網地址下載: html
http://logback.qos.ch/download.html tomcat
二、解壓後,將logback-access.jar與logback-core.jar複製到$TOMCAT_HOME/lib/目錄下 app
修改$TOMCAT_HOME/conf/server.xml添加: spa
1
|
<ValveclassName="ch.qos.logback.access.tomcat.LogbackValve"/>
|
必須添加在<Engine>或<Host>結點下。 code
三、logback默認會在$TOMCAT_HOME/conf下查找文件 logback-access.xml server
新建 logback-access.xml 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便可。 htm