在logback的fileNamePattern配置%i 带来的异常

我在logback的配置文件中企图这样配置:

        <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>

但是出现了以下异常:

复制代码
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就好了,需要整体替换:

        <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也能正确书写:

复制代码
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.zip

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

posted @   逆火狂飙  阅读(10687)  评论(2编辑  收藏  举报
编辑推荐:
· 智能桌面机器人:用.NET IoT库控制舵机并多方法播放表情
· Linux glibc自带哈希表的用例及性能测试
· 深入理解 Mybatis 分库分表执行原理
· 如何打造一个高并发系统?
· .NET Core GC压缩(compact_phase)底层原理浅谈
阅读排行:
· 手把手教你在本地部署DeepSeek R1,搭建web-ui ,建议收藏!
· 新年开篇:在本地部署DeepSeek大模型实现联网增强的AI应用
· 程序员常用高效实用工具推荐,办公效率提升利器!
· Janus Pro:DeepSeek 开源革新,多模态 AI 的未来
· 【译】WinForms:分析一下(我用 Visual Basic 写的)
历史上的今天:
2017-01-17 用df命令显示磁盘使用量和占用率。
2014-01-17 在centOS上安装VNC
2014-01-17 SCP远程拷贝命令
2014-01-17 【Canvas技法】绘制圆角六边形
2014-01-17 【高中数学/对数函数/大小比较】设a=2/ln2,b=3/ln3,c=e,则a,b,c的大小关系为?
生当作人杰 死亦为鬼雄 至今思项羽 不肯过江东
点击右上角即可分享
微信分享提示