I am trying to get Spring Boot working with Logback and am running into an error/issue that I can't figure out.
To reproduce this issue in its entirety, I created a Spring Boot Example repo on GitHub, but essentially, this is my application.yml
:
logging:
config: 'logback.groovy'
server:
port: 9200
error:
whitelabel:
enabled: false
And my logback.groovy
:
statusListener(OnConsoleStatusListener)
def LOG_PATH = '/opt/springbootexample/logs/springbootexample'
appender('CONSOLE', ConsoleAppender) {
encoder(PatternLayoutEncoder) {
pattern = '%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n'
}
}
appender('FILE', FileAppender) {
file = "${LOG_PATH}.log"
encoder(PatternLayoutEncoder) {
pattern = '%msg%n'
outputPatternAsHeader = true
}
}
appender('ROLLING', RollingFileAppender) {
encoder(PatternLayoutEncoder) {
Pattern = '%d %level %thread %mdc %logger - %m%n'
}
rollingPolicy(TimeBasedRollingPolicy) {
fileNamePattern = "${LOG_PATH}-%d{yyyy-MM}.zip"
maxHistory = 30
totalSizeCap = '1KB'
}
}
root(INFO, ["CONSOLE", "ROLLING"])
I've made sure that /opt/springbootexample/logs
exists I ran chmod -R 777 /opt/springbootexample
so my Spring Boot app should have no problem creating log files there and writing to them.
When I run the app locally, I get no errors/exceptions/warnings; everything looks perfectly fine in the console output. I then fire up a browser and point it to http://localhost:9200
, which should return a simple dummy message, however nothing happens. Even worse, nothing in the console happens either.
The only clue is that after I've shut down the app, if I go to /opt/springbootexample/logs/springbootexample.log
, its contents are:
#logback.classic pattern: %msg%n
Which tells me that perhaps there's something misconfigured in my logback.groovy
's FileAppender
maybe? Any ideas/thoughts?