You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fun configureLogback() {
// reset the default context (which may already have been initialized)
// since we want to reconfigure it
val context = LoggerFactory.getILoggerFactory() as LoggerContext
context.reset()
val appDir: File = getWorkDirectory()
val LOG_DIR = "$appDir/logback/"
// Enable debugging to show rollover status
// OnConsoleStatusListener.addNewInstanceToContext(context)
// val LOG_DIR = "/sdcard/logback"
val rollingFileAppender = RollingFileAppender()
rollingFileAppender.isAppend = true
rollingFileAppender.context = context
// OPTIONAL: Set an active log file (separate from the rollover files).
// If rollingPolicy.fileNamePattern already set, you don't need this.
rollingFileAppender.file = "$LOG_DIR/log.txt"
// Set the periodicity to seconds. That is, if a log event occurs after the
// second-boundary, the log file will rollover.
val PERIODICITY = "yyyy-MM-dd_HH-mm-ss"
val rollingPolicy = TimeBasedRollingPolicy<ILoggingEvent>()
rollingPolicy.fileNamePattern = "$LOG_DIR/log.%d{$PERIODICITY}.txt"
rollingPolicy.maxHistory = 7 // no more than 5 rollover files (delete oldest)
rollingPolicy.setParent(rollingFileAppender) // parent and context required!
rollingPolicy.context = context
rollingPolicy.start()
rollingFileAppender.rollingPolicy = rollingPolicy
val encoder = PatternLayoutEncoder()
encoder.pattern = "%logger{35} - %msg%n"
encoder.context = context
encoder.start()
rollingFileAppender.setEncoder(encoder)
rollingFileAppender.start()
// add the newly created appenders to the root logger;
// qualify Logger to disambiguate from org.slf4j.Logger
val root =
LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME) as ch.qos.logback.classic.Logger
root.level = Level.TRACE
root.addAppender(rollingFileAppender)
}
I have (only in release mode, it works in android) this exception:
java.lang.RuntimeException: Unable to create application it.soluzione1.pevianiwms.MyCustomApplication: java.lang.IllegalStateException: FileNamePattern [/storage/emulated/0/Android/data/it.soluzione1.pevianiwms/files/logback/log.%d{yyyy-MM-dd_HH-mm-ss}.txt] does not contain a valid DateToken
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6785)
at android.app.ActivityThread.access$1400(ActivityThread.java:241)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1929)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7747)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:952)
Caused by: java.lang.IllegalStateException: FileNamePattern [/storage/emulated/0/Android/data/it.soluzione1.pevianiwms/files/logback/log.%d{yyyy-MM-dd_HH-mm-ss}.txt] does not contain a valid DateToken
at x4.a.start(SourceFile:29)
at x4.d.start(SourceFile:174)
at it.soluzione1.pevianiwms.utils.Utility$Companion.configureLogback(SourceFile:80)
at it.soluzione1.pevianiwms.MyCustomApplication.onCreate(SourceFile:85)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1193)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6780)
at android.app.ActivityThread.access$1400(ActivityThread.java:241)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1929)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7747)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:952)
Reproduction
Call the method in the Application class
Logs
No response
logback-android version
2.0.1
OS Version
Android 11
What logback configuration are you using? (logback.xml or Java/Kotlin code)
The configuration is in the code
Validations
Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
Describe the bug
Using this code
fun configureLogback() {
// reset the default context (which may already have been initialized)
// since we want to reconfigure it
val context = LoggerFactory.getILoggerFactory() as LoggerContext
context.reset()
val appDir: File = getWorkDirectory()
val LOG_DIR = "$appDir/logback/"
// OnConsoleStatusListener.addNewInstanceToContext(context)
// val LOG_DIR = "/sdcard/logback"
val rollingFileAppender = RollingFileAppender()
rollingFileAppender.isAppend = true
rollingFileAppender.context = context
I have (only in release mode, it works in android) this exception:
Reproduction
Call the method in the Application class
Logs
No response
logback-android version
2.0.1
OS Version
Android 11
What logback configuration are you using? (logback.xml or Java/Kotlin code)
Validations
The text was updated successfully, but these errors were encountered: