我正在实现对我的应用程序的日志记录,我正在尝试将模式添加到我的日志文件appender中,
我的代码是这样的:
log4j = {
appenders {
// append new appenders of your own and add log level and packages/files like to add.
rollingFile name: "myAppender",
maxFileSize: 1024,
file: "C:/GrailsWS/BaseGrails/target/basegrails.log"//""basegrails.log" // C:\GrailsWS\BaseGrails\target\basegrails.log
console name: "myAppender",
layout: pattern(conversionPattern: "%c{2} %m%n")
}
我正在关注Grails Logging页面,在添加模式行后,我的basegrails.log没有获取任何日志数据。
答案 0 :(得分:1)
你不想拥有同名的追加者。我相信你想要做的是给你的appender不同的名字,然后根据需要应用转换模式。如果需要,可以使用通用模式定义变量。所以,像:
log4j = {
def commonPattern = "%c{2} %m%n"
appenders {
// append new appenders of your own and add log level and packages/files like to add.
rollingFile name: "rollingLog",
maxFileSize: 1024,
file: "C:/GrailsWS/BaseGrails/target/basegrails.log",
layout: pattern(conversionPattern: commonPattern)
console name: "stdout",
layout: pattern(conversionPattern: commonPattern )
}
// then, use your appenders
trace stdout ['grails.app', ...]
debug rollingFile: ['your.package', ...]
}