如何使用tomcat 8设置Logback?

时间:2016-07-21 15:41:21

标签: tomcat logback

我仍然面临使用tomcat8配置Logback的问题。我想我错过了一点。

  

在我的pom.xml中:

<!-- Logging --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.2</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>jcl-over-slf4j</artifactId> <version>1.7.2</version> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>1.1.7</version> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-core</artifactId> <version>1.1.7</version> </dependency>

我在server.xml文件中添加了阀门:

<Valve  className="org.apache.catalina.valves.AccessLogValve"
                        directory="logs" 
                        prefix="localhost_access_log" 
                        suffix=".txt"
                        pattern="%h %l %u %t &quot;%r&quot; %s %b" />
  

在logback.xml中

<?xml version="1.0" encoding="UTF-8"?>    
<configuration scan="true">

    <property name="max.retention.days" value="60" />

    <appender name="GLOBAL_OUTPUT" class="org.apache.juli.logging.ch.qos.logback.core.rolling.RollingFileAppender">
        <file>global.log</file>
        <append>true</append>
        <encoder>
            <charset>utf-8</charset>
            <pattern>%d{HH:mm:ss.SSS} %-5level {%thread} [%logger{40}] : %msg%n</pattern>
        </encoder>
        <rollingPolicy class="org.apache.juli.logging.ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${catalina.base}/logs/archive/global.log-%d{yyyyMMdd}-%i.log.zip</fileNamePattern>

            <maxHistory>${max.retention.days}</maxHistory>
            <cleanHistoryOnStart>true</cleanHistoryOnStart>
        </rollingPolicy>
    </appender>    

    <logger name="org.apache.catalina" level="INFO">
        <appender-ref ref="GLOBAL_OUTPUT" />
    </logger>


</configuration>
     

然后在我的logback-access.xml中:

<property name="max.retention.days" value="60" />

<appender name="ACCESS-LOG" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>${catalina.base}/logs/localhost-access.log</file>
    <append>true</append>
    <encoder class="ch.qos.logback.access.PatternLayoutEncoder">
        <charset>utf-8</charset>
        <pattern>common</pattern>
    </encoder>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <fileNamePattern>${catalina.base}/logs/archive/localhost-access-%d{yyyyMMdd}-%i.log.zip</fileNamePattern>

        <maxHistory>${max.retention.days}</maxHistory>
        <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
            <maxFileSize>20MB</maxFileSize> 
        </timeBasedFileNamingAndTriggeringPolicy>
    </rollingPolicy>
</appender>

<appender-ref ref="ACCESS-LOG" />
     

     

这就是错误:

     

org.apache.jasper.servlet.TldScanner.scanJars至少有一个JAR是   扫描TLD但尚未包含TLD。为此启用调试日志记录   记录器获取已扫描但没有TLD的JAR的完整列表   发现在他们身上。在扫描期间跳过不需要的JAR可以改善   启动时间和JSP编译时间。

感谢您的帮助, Swaye

0 个答案:

没有答案