logback.groovy 配置不记录任何内容
我有以下 logback.groovy 配置文件,我似乎无法理解为什么它没有执行我希望它执行的操作。理想情况下,TRACE 或以上的每条消息都应记录到文件中,而 WARN 或以上的任何消息都将立即显示在标准输出上。不幸的是,我似乎根本无法让这一切发生。有什么想法吗?
import ch.qos.logback.classic.encoder.PatternLayoutEncoder
import ch.qos.logback.core.ConsoleAppender
import ch.qos.logback.core.FileAppender
import static ch.qos.logback.classic.Level.TRACE
import static ch.qos.logback.classic.Level.WARN
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.foo", WARN, ["STDOUT"])
root(TRACE, ["FILE"])
谢谢!
I have the following logback.groovy configuration file, and I can't seem to understand why it isn't doing what I would like it to do. Ideally, every message at TRACE or above should get logged to a file, and anything at WARN or above will get immediately shown on stdout. Unfortunately, I can't seem to get this to happen at all. Any ideas?
import ch.qos.logback.classic.encoder.PatternLayoutEncoder
import ch.qos.logback.core.ConsoleAppender
import ch.qos.logback.core.FileAppender
import static ch.qos.logback.classic.Level.TRACE
import static ch.qos.logback.classic.Level.WARN
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.foo", WARN, ["STDOUT"])
root(TRACE, ["FILE"])
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 logback.groovy 文件的开头添加以下行(就在上次导入之后)
Add the following line at the beginning of your logback.groovy file (just after the last import)