I basically followed the instruction in Chapter 7 of the official logback documentation. Unfortunately, things don't seem to work properly, and I can't figure out why. So, here we are.
What I want to achieve is to log only info and above in console and all debug and above into log files. I have these lines in my logback.groovy
:
appender("CONSOLE", ConsoleAppender) {
encoder(PatternLayoutEncoder) {
pattern = "%d{YYYY-MM-dd/HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n"
}
filter(ThresholdFilter) {
level = INFO
}
}
logger("vh.FileIO", DEBUG, ['CONSOLE','FILE-DEBUG'])
root(DEBUG, ['CONSOLE'])
I thought the ThresholdFilter
would make CONSOLE
only take info and above logs. However, I still get debug logs of vh.FileIO
on the CONSOLE
. For example, I still get something like this on the console:
2013-10-11/21:48:10.537 [main] DEBUG vh.FileIO - Combining all records into file ./output/sip_sample_data_output.csv
So, what am I missing here?
After playing with the configuration of logback, I find that the ThresholdFilter works as expected if I use an XML configuration file. However, I still would like to know why it's not working in the groovy configuration file.
Solution for the problem is the following: just add import of the class ThresholdProvider at the beginning of "logback.groovy":
import ch.qos.logback.classic.filter.ThresholdFilter
then it works as expected.
I tried the provided "logback.groovy" on a simple project. There's another problem: messages are written twice to the console. I think this could be fixed by fine-tuning "logger" and "root" calls.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With