如何使用 logback.groovy 文件将 TRACE 级别记录到文件并将 INFO 记录到控制台
我正在尝试使日志调用将不同级别的输出定向到不同的位置。我希望所有日志始终转到文件,而仅将 INFO 及以上日志转到控制台。那不可能吗?我有以下内容,但它不起作用。两者总是相同的:
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()
是否可以根据不同级别将相同的日志消息定向到两个不同的位置?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
向两个附加程序发送跟踪
,但向
ConsoleAppender
添加过滤器send trace to both appenders
but add a filter to the
ConsoleAppender