开发者

How do I use logback.groovy file to log TRACE level to file and INFO to console

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?


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
  }
  ...
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜