You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Logback配置报错:解析整数失败,请求排查%C{1.}格式问题

Logback配置报错排查:NumberFormatException

报错信息

Logging system failed to initialize using configuration from 'null'
java.lang.IllegalStateException: Logback configuration error detected: 
ERROR in ch.qos.logback.classic.pattern.ClassOfCallerConverter@436e641b - failed to parse integer string [1.] java.lang.NumberFormatException: For input string: "1."

问题根源

报错直接指向配置里的%C{1.}格式符:

  • %C是Logback用于输出调用日志方法的完整类名的格式符
  • 后面的{N}是可选参数,用来指定只显示类名的最后N个层级(比如com.example.MyClass用%C{1}会显示MyClass,%C{2}显示example.MyClass)
  • 你写的{1.}多了个英文句号,导致Logback试图把字符串"1."转换成整数时失败,抛出NumberFormatException

修正方案

把配置里的%yellow(%C{1.})改成%yellow(%C{1})即可。另外补充两个格式符的区别:

  • %C:输出代码中实际调用日志的类的完整类名(性能稍差,需要遍历栈)
  • %c:输出当前logger实例的名称(通常就是类名,性能更好)

修正后的完整配置

<?xml version="1.0" encoding="UTF-8"?>
<configuration>

    <property name="LOGS" value="./logs" />

    <appender name="Console"
        class="ch.qos.logback.core.ConsoleAppender">
        <layout class="ch.qos.logback.classic.PatternLayout">
            <Pattern>
                %black(%d{ISO8601}) %highlight(%-5level) [%blue(%t)] %yellow(%C{1}): %msg%n%throwable
            </Pattern>
        </layout>
    </appender>    
    
    <!-- LOG everything at INFO level -->
    <root level="info">        
        <appender-ref ref="Console" />
    </root>
   
</configuration>

内容的提问来源于stack exchange,提问作者itsraja

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 22:16:18