spring boot 日誌配置

1.新建logback.xml文件html

 

內容以下:spring

<!-- Logback configuration. See http://logback.qos.ch/manual/index.html -->
<configuration scan="true" scanPeriod="10 seconds">
    <include resource="org/springframework/boot/logging/logback/base.xml" />

    <appender name="INFO_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <File>${LOG_PATH}/info.log</File>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${LOG_PATH}/info-%d{yyyyMMdd}.log.%i</fileNamePattern>
            <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>500MB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
            <maxHistory>2</maxHistory>
        </rollingPolicy>
        <layout class="ch.qos.logback.classic.PatternLayout">
            <Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} -%msg%n
            </Pattern>
        </layout>
    </appender>

    <appender name="ERROR_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>ERROR</level>
        </filter>
        <File>${LOG_PATH}/error.log</File>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${LOG_PATH}/error-%d{yyyyMMdd}.log.%i
            </fileNamePattern>
            <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>500MB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
            <maxHistory>2</maxHistory>
        </rollingPolicy>
        <layout class="ch.qos.logback.classic.PatternLayout">
            <Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} -%msg%n

            </Pattern>
        </layout>
    </appender>
    
    <!-- hibernate日誌輸入 -->
    <!-- <logger name="org.hibernate.type.descriptor.sql.BasicBinder"
        level="TRACE" />
    <logger name="org.hibernate.type.descriptor.sql.BasicExtractor"
        level="TRACE" />
    <logger name="org.hibernate.SQL" level="INFO" />
    <logger name="org.hibernate.engine.QueryParameters" level="INFO" />
    <logger name="org.hibernate.engine.query.HQLQueryPlan" level="INFO" /> -->

    <root level="INFO">
        <appender-ref ref="INFO_FILE" />
        <appender-ref ref="ERROR_FILE" />
    </root>
    
</configuration>

 

2.而後在application.properties文件中假如以下代碼:sql

#log
logging.config=classpath:logback.xml
logging.path=/workspace/rock/jpa-test/log

3.這時就能夠使用log對象了app

private final Logger log = Logger.getLogger(this.getClass());

log.info("你妹");

:因爲個人項目在d盤,因此第二步設置的文件路徑爲:d:/workspace/rock/jpa-test/logthis

運行程序後,進入路徑會有三個文件spa

好了,此處有兩個連接,供你們參考:.net

http://blog.csdn.net/zgmzyr/article/details/8267072hibernate

http://www.mamicode.com/info-detail-1149964.html日誌

在此感謝原文做者!code

相關文章
相關標籤/搜索