gpt4 book ai didi

java - Logback 给出错误 Cannot cast object '3 gb' with class 'java.lang.String' to class 'ch.qos.logback.core.util.FileSize'

转载 作者:搜寻专家 更新时间:2023-11-01 02:03:27 25 4
gpt4 key购买 nike

我有一个 springboot 应用程序,在尝试使用带有 groovy 配置的 logback 进行登录时,我收到以下错误:

    Failed to instantiate [ch.qos.logback.classic.LoggerContext]
Reported exception:
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '3 gb' with class 'java.lang.String' to class 'ch.qos.logback.core.util.FileSize'
at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnSAM(DefaultTypeTransformation.java:405)
at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnNumber(DefaultTypeTransformation.java:319)

我的常规配置文件:

import ch.qos.logback.classic.PatternLayout
import static ch.qos.logback.classic.Level.INFO

scan("60 seconds")
def LOG_PATH = "logs"
def LOG_ARCHIVE = "${LOG_PATH}/archive"



appender("RollingFile-Appender", RollingFileAppender) {
file = "${LOG_PATH}/rollingfile.log"
rollingPolicy(TimeBasedRollingPolicy) {
fileNamePattern = "${LOG_ARCHIVE}/Rainbow_Notifications.log%d{yyyy-MM-dd}.log"
maxHistory = 30
totalSizeCap = "3 gb"
}
encoder(PatternLayoutEncoder) {
pattern = "%msg%n"
}
}


logger("com.something", INFO, ["RollingFile-Appender"])

注意:我什至尝试过这些字符串:as file size: 3gb, 3 gb, 3GB ,3096mb,3096mb,3096MB

最佳答案

尝试更换线路

    totalSizeCap = "3 gb"

    totalSizeCap = FileSize.valueOf("3 gb")

您还需要添加行 import ch.qos.logback.core.util.FileSize;

setTotalSizeCap method of the TimeBasedRollingPolicy class需要 FileSize对象,而不是字符串。 FileSize 中的静态 valueOf 方法应该执行从字符串到 FileSize 的必要转换。

关于java - Logback 给出错误 Cannot cast object '3 gb' with class 'java.lang.String' to class 'ch.qos.logback.core.util.FileSize',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40161937/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com