Error issuing protocol. Cannot transfer object "3 gb" with class "java.lang.String" to class "ch.qos.logback.core.util.FileSize"

I have a springboot application and when I try to log in using logback with groovy configuration, I get the following error:

    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)

My groovy configuration file:

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"])

Note: I tried even these lines: as the size of the file: 3gb, 3 gb, 3gb, 3096mb, 3096 mb,3096 mb

+4
source share
1 answer

Try replacing the string

    totalSizeCap = "3 gb"

with

    totalSizeCap = FileSize.valueOf("3 gb")

You also need to add a line import ch.qos.logback.core.util.FileSize;.

setTotalSizeCap TimeBasedRollingPolicy FileSize , . valueOf FileSize FileSize.

+6

Source: https://habr.com/ru/post/1658367/


All Articles