在logback的fileNamePattern配置%i 帶來的異常

我在logback的配置文件中企圖這樣配置:java

<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!--log file pathname -->
            <FileNamePattern>${LOG_HOME}/MmSpringWebApplication.%d{yyyy-MM-dd}%i.log </FileNamePattern>
            <!--days log files will be kept -->
            <MaxHistory>30</MaxHistory>
        </rollingPolicy>

可是出現瞭如下異常:spring

Exception in thread "main" java.lang.IllegalStateException: Logback configuration error detected: ERROR in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Filename pattern [d:/logs/MmSpringWebApplication.%d{yyyy-MM-dd}%i.log] contains an integer token converter, i.e. %i, INCOMPATIBLE with this configuration. Remove it. ERROR in ch.qos.logback.core.joran.spi.Interpreter@37:13 - RuntimeException in Action for tag [appender] java.lang.IllegalArgumentException: Cannot convert Fri Jan 17 11:38:15 JST 2020 of typejava.util.Date at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:169) at org.springframework.boot.logging.logback.LogbackLoggingSystem.reinitialize(LogbackLoggingSystem.java:222) at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithConventions(AbstractLoggingSystem.java:73) at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:60) at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:118) at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:312) at org.springframework.boot.context.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:287) at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:245) at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:222) at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127) at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:76) at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:53) at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:345) at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) at MmSpringWebApplication.main(MmSpringWebApplication.java:16)

要修正也簡單,不是僅僅添加%i就行了,須要總體替換:app

<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <fileNamePattern>${LOG_HOME}/logbackCfg3.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
            <maxFileSize>1000MB</maxFileSize>
            <MaxHistory>60</MaxHistory>
        </rollingPolicy>

這樣就%i就不會報有異常的,log也能正確書寫:this

2020-01-17 11:50:33.706 [main] ERROR logbackCfg.App2 -牧童拾得舊刀槍 2020-01-17 11:50:33.706 [main] DEBUG logbackCfg.App2 -微風吹皺烏江水 2020-01-17 11:50:33.706 [main] TRACE logbackCfg.App2 -恰似虞姬別霸王 2020-01-17 11:50:35.836 [main] INFO logbackCfg.App -秦時明月漢時關 2020-01-17 11:50:35.836 [main] ERROR logbackCfg.App -萬里長征人未還 2020-01-17 11:50:35.836 [main] DEBUG logbackCfg.App -但使龍城飛將在 2020-01-17 11:50:35.836 [main] TRACE logbackCfg.App -不教胡馬度陰山 2020-01-17 11:50:40.836 [main] INFO logbackCfg.App -秦時明月漢時關 2020-01-17 11:50:40.836 [main] ERROR logbackCfg.App -萬里長征人未還 2020-01-17 11:50:40.836 [main] DEBUG logbackCfg.App -但使龍城飛將在 2020-01-17 11:50:40.836 [main] TRACE logbackCfg.App -不教胡馬度陰山 2020-01-17 11:50:41.706 [main] INFO logbackCfg.App2 -九里山前做戰場 2020-01-17 11:50:41.706 [main] ERROR logbackCfg.App2 -牧童拾得舊刀槍 2020-01-17 11:50:41.706 [main] DEBUG logbackCfg.App2 -微風吹皺烏江水 2020-01-17 11:50:41.706 [main] TRACE logbackCfg.App2 -恰似虞姬別霸王 2020-01-17 11:50:42.682 [main] INFO logbackCfg.NewDayThread -萬里赴戎機,關山度若飛。 2020-01-17 11:50:42.685 [main] ERROR logbackCfg.NewDayThread -朔氣傳金柝,寒光照鐵衣。 2020-01-17 11:50:42.685 [main] DEBUG logbackCfg.NewDayThread -將軍百戰死,壯士十年歸。 2020-01-17 11:50:45.836 [main] INFO logbackCfg.App -秦時明月漢時關 2020-01-17 11:50:45.836 [main] ERROR logbackCfg.App -萬里長征人未還 2020-01-17 11:50:45.836 [main] DEBUG logbackCfg.App -但使龍城飛將在 2020-01-17 11:50:45.836 [main] TRACE logbackCfg.App -不教胡馬度陰山 2020-01-17 11:50:49.706 [main] INFO logbackCfg.App2 -九里山前做戰場 2020-01-17 11:50:49.706 [main] ERROR logbackCfg.App2 -牧童拾得舊刀槍 2020-01-17 11:50:49.706 [main] DEBUG logbackCfg.App2 -微風吹皺烏江水

例程下載:https://files.cnblogs.com/files/xiandedanteng/logbackCfg3-2020-01-17.zipurl

--END-- 2020-01-17 11:58spa

相關文章
相關標籤/搜索