I am trying to make a log call direct different levels of output to different locations. I want all the logs to always go to the file, and just INFO and above to go to console. Is that not possible? I have the following and it doesn't work. Both are always the same:
def bySecond = timestamp("yyyyMMdd'.'HHmmss", context.birthTime)
appender("STDOUT", ConsoleAppender) {
encoder(PatternLayoutEncoder) {
pattern = "%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n"
}
}
appender("FILE", FileAppender) {
file = "./logs/log-${bySecond}.log"
encoder(PatternLayoutEncoder) {
pattern = "%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n"
}
}
logger("com.crystal", WARN, ["STDOUT"])
logger("com.crystal", TRACE, ["FILE"])
root(TRACE)
scan()
Is it possible to direct the same log message to two different places based off different levels?
To create a configuration for Logback, you can use XML as well as Groovy. The system will automatically pick up and use the configuration automatically, as long as you're adhering to the naming convention. There are three valid standard file names you can choose from: logback-test.
In a Logback. xml file, all the configuration options are enclosed within the <configuration> root element. In the root element, you can set the debug=true attribute to inspect Logback's internal status. You can also configure auto scanning of the configuration file by setting the scan=true attribute.
send trace to both appenders
logger 'com.crystal', TRACE, ['STDOUT', 'FILE']
but add a filter to the ConsoleAppender
appender("FILE", FileAppender) {
filter(ch.qos.logback.classic.filter.ThresholdFilter) {
level = INFO
}
...
}
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