springboot log configuration Spring Boot Series - Logging Configuration

springboot default is logback to remember log. Every time I see the first print out the log when you start the following services:

"C:\Program Files\Java\jdk1.8.0_40\bin\java.exe" ...
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/D:/workspace/m3/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/D:/workspace/m3/org/slf4j/slf4j-log4j12/1.7.26/slf4j-log4j12-1.7.26.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]

、、、各种初始化、、、
、、、接下来是那个熟悉的图标、、、

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.1.7.RELEASE)

 

If you do not do the logging configuration, the default is to generate spring.log in service.

 

To customize the logging configuration, simply put, can make use logging.file or logging.path make the following settings in application.properties in:

logging.file=logs/draft_spider.log
logging.level.com.draft.mapper= debug

 

Because a large amount of log different business systems, in order to facilitate rapid positioning of logs to troubleshoot problems, I want to print a business in a particular log file. Then, create logback.xml in the resources of the project, detailed logging.

<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="false" scanPeriod="300 seconds" debug="true">
    <!--本地日志目录-->
    <property name="USER_HOME" value="logs/"/>
    <property name="LOG_MSG" value="%X{sid}%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5p [%c:%L] - %m%n"/>
    <property name="LOG_DIR" value="${USER_HOME}/%d{yyyyMMdd}"/>

    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>${LOG_MSG}</pattern>
        </encoder>
    </appender>

    <appender name="INFO_LOG" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${USER_HOME}/spider_info.log</file>
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>INFO</level>
        </filter>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${LOG_DIR}/spider_info%i.log</fileNamePattern>
            <TimeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>20MB</maxFileSize>
            </TimeBasedFileNamingAndTriggeringPolicy>
        </rollingPolicy>
        <encoder>
            <pattern>${LOG_MSG}</pattern>
        </encoder>
    </appender>
    <appender name="ORDERLIST_SPIDER_LOG" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${USER_HOME}/orderlist_spider.log</file>
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>INFO</level>
        </filter>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${LOG_DIR}/orderlist_spider%i.log</fileNamePattern>
            <TimeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>20MB</maxFileSize>
            </TimeBasedFileNamingAndTriggeringPolicy>
        </rollingPolicy>
        <encoder>
            <pattern>${LOG_MSG}</pattern>
        </encoder>
    </appender>

    <appender name="ERROR_LOG" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${USER_HOME}/spider_error.log</file>
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>ERROR</level>
        </filter>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${LOG_DIR}/spider_error%i.log</fileNamePattern>
            <TimeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>20MB</maxFileSize>
            </TimeBasedFileNamingAndTriggeringPolicy>
        </rollingPolicy>
        <encoder>
            <pattern>${LOG_MSG}</pattern>
        </encoder>
    </appender>

    <! -<logger name="druid.sql.Statement" level="DEBUG" additivity="false">-->
    <!--<appender-ref ref="SQL_LOG"/>-->
    <!--</logger>-->
    <logger name="spiderLog" level="DEBUG" additivity="false">
        <appender-ref ref="ORDERLIST_SPIDER_LOG"/>
    </logger>
    <logger name="com.draft.processor.TcpjwPageProcessor" level="DEBUG" additivity="false">
        <appender-ref ref="ORDERLIST_SPIDER_LOG"/>
    </logger>
    <logger name="com.draft.task.SpiderTaskPage" level="DEBUG" additivity="false">
        <appender-ref ref="ORDERLIST_SPIDER_LOG"/>
    </logger>
    <logger name="com.draft.task.SpiderTask" level="DEBUG" additivity="false">
        <appender-ref ref="ORDERLIST_SPIDER_LOG"/>
    </logger>

    <root level="INFO">
        <appender-ref ref="STDOUT"/>
        <appender-ref ref="ERROR_LOG"/>
        <appender-ref ref="INFO_LOG"/>
        <!--<appender-ref ref="ORDERLIST_SPIDER_LOG"/>-->
    </root>
</configuration>

 

 

ref: the Spring the Boot Series - Logging Configuration

 

Guess you like

Origin www.cnblogs.com/buguge/p/11469122.html