简体   繁体   中英

Configure logback through Eclipse for Tomcat logging

I configured my logback.xml to create a ATSLog.log file and save every day a log file with the date.

    <?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <appender name="consoleAppender" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <Pattern>.%d{yyyy-MM-dd}.%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg %n
            </Pattern>
        </encoder>
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>TRACE</level>
        </filter>
    </appender>
    <appender name="dailyRollingFileAppender"
        class="ch.qos.logback.core.rolling.RollingFileAppender">
        <File>${CATALINA_HOME}/logs/ATSLog.log</File>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!-- daily rollover -->
            <FileNamePattern>${CATALINA_HOME}/logs/ATSLog_%d{yyyy-MM-dd}.%i.log
            </FileNamePattern>

            <!-- keep 30 days' worth of history -->
            <maxHistory>30</maxHistory>
        </rollingPolicy>

        <encoder>
            <Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{35} - %msg %n
            </Pattern>
        </encoder>
    </appender>
    <logger name="org.hibernate.type" level="ERROR" />
    <logger name="org.hibernate" level="ERROR" />
    <root>
        <level value="INFO" />
        <appender-ref ref="dailyRollingFileAppender" />
        <appender-ref ref="consoleAppender" />
    </root>
</configuration>

But in my /opt/apache-tomcat-8.0.26/logs I find only one old ATSLog.log and no other log saved. Do you see an error in my configuration? Thanks

Make sure you have added CATALINA_BASE in you environment variables. In your config file you have specified the log file path relative to CATALINA_BASE using the expression ${catalina.base} . If its not in environment variables, try adding it. If not set, you can probably expect the logs in /log/ATSLogs.log .

Try this project: https://github.com/grgrzybek/tomcat-slf4j-logback

This project provides the necessary JAR files and configuration files to integrate you instance of Tomcat with SLF4J + Logback, replacing the logging code embedded within the default Tomcat distribution. Refer to the Quick Start section of that project's README for instructions and download links.

I've used it on production and Eclipse environments with much success. Note the extra steps at the bottom of the project's README file for Eclipse environments.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM