pom

<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>RELEASE</version>
</dependency>

配置文件 bootstrap.properties

logging.config=classpath:logback.xml
logback.log.home=/logs/neusoft
logback.log.level=DEBUG
logback.log.framework.level=INFO

logback.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <!-- 定义日志文件的存储地址 -->
    <property name="LOG_HOME" value="${logback.log.home}/basic" />
    <!--定义日志文件的备份文件地址 -->
    <property name="LOG_BACK_HOME" value="${logback.log.home}/basic/backup" />
    <!-- 日志输出级别 TRACE, DEBUG, INFO, WARN, ERROR, ALL OFF -->
    <property name="LOG_FRAMEWORK_LEVEL" value="${logback.log.framework.level}" />
    <property name="LOG_LEVEL" value="${logback.log.level}" />
    <!-- 历史log文件最多保留天数 -->
    <property name="LOG_FILE_MAXHISTORY" value="7" />
    <!-- 文件大小 -->
    <property name="LOG_FILE_MAXSIZE" value="50MB" />

    <!-- 格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符 -->
    <property name="LOG_PATTERN"
              value='%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread] %logger{50}: %msg %n' />

    <!-- 控制台 日志 -->
    <appender name="CONSOLE_LOG" class="ch.qos.logback.core.ConsoleAppender">
        <!-- 临界值过滤器 -->
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>${LOG_LEVEL}</level>
        </filter>
        <!-- encoder 默认layout : ch.qos.logback.classic.PatternLayout -->
        <encoder>
            <pattern>${LOG_PATTERN}</pattern>
        </encoder>
    </appender>

    <!-- Log文件 日志 -->
    <appender name="FILE_LOG" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${logback.log.home}/basic/basic.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${LOG_BACK_HOME}/basic-%d{yyyy-MM-dd}-%i.log.zip
            </fileNamePattern>
            <maxHistory>${LOG_FILE_MAXHISTORY}</maxHistory>
            <timeBasedFileNamingAndTriggeringPolicy
                    class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>${LOG_FILE_MAXSIZE}</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
        </rollingPolicy>
        <encoder>
            <pattern>${LOG_PATTERN}</pattern>
        </encoder>
    </appender>

    <logger name="com.neusoft" level="${LOG_LEVEL}" additivity="false">
        <appender-ref ref="CONSOLE_LOG"/>
        <appender-ref ref="FILE_LOG"/>
    </logger>

    <root level="${LOG_FRAMEWORK_LEVEL}">
        <appender-ref ref="CONSOLE_LOG"/>
        <appender-ref ref="FILE_LOG"/>
    </root>
</configuration>