logback-access 的使用

logback-access模块与Servlet容器(如Tomcat和Jetty)集成,以提供HTTP访问日志功能。我们可以使用logback-access模块来替换tomcat的访问日志。

  1. 将logback-access.jar与logback-core.jar复制到$TOMCAT_HOME/lib/目录下
  2. 修改$TOMCAT_HOME/conf/server.xml中的Host元素中添加:
<Valve className="ch.qos.logback.access.tomcat.LogbackValve" />
  1. logback默认会在$TOMCAT_HOME/conf下查找文件 logback-access.xml
<?xml version="1.0" encoding="UTF-8"?> 
<configuration> 
    <!-- always a good activate OnConsoleStatusListener --> 
    <statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener"/> 
    <property name="LOG_DIR" value="${catalina.base}/logs"/> 
    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> 
        <file>${LOG_DIR}/access.log</file> 
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> 
            <fileNamePattern>access.%d{yyyy-MM-dd}.log.zip</fileNamePattern> 
        </rollingPolicy>
    <encoder> 
        <!-- 访问日志的格式 --> 
        <pattern>combined</pattern> 
    </encoder> </appender> 
    <appender-ref ref="FILE"/> 
</configuration>
  1. 官方配置: https://logback.qos.ch/access.html#configuration
上一篇:log4j.properties怎么转换成logback.xml


下一篇:logback.xml