How to use logback.groovy file to register TRACE level for file and INFO for console

I am trying to make a logical call direct to different output levels in different places. I want all the logs to always access the file, but only INFO and above to go to the console. Is it impossible? I have the following and it will not 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 send the same journal message to two different places based on different levels?

+6
source share
1 answer

send trace to both applications

 logger 'com.crystal', TRACE, ['STDOUT', 'FILE'] 

but add filter to ConsoleAppender

 appender("FILE", FileAppender) { filter(ch.qos.logback.classic.filter.ThresholdFilter) { level = INFO } ... } 
+6
source

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


All Articles