zoukankan      html  css  js  c++  java
  • 在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

  • 相关阅读:
    jQuery使用手册之Ajax支持(8)
    jQuery使用手册之动态效果(6)
    jquery插件 操作select
    提高jQuery的性能
    jQuery起点教程之使用AJAX(4)
    jQuery起点教程之插件制作(7)
    IE开发工具栏
    信息安全之DNS欺骗详解
    颜色取色器
    使DIV不被select等控件遮挡的解决办法
  • 原文地址:https://www.cnblogs.com/heyang78/p/12204769.html
Copyright © 2011-2022 走看看