我正在实现对应用程序的日志记录,我正在尝试向日志文件追加程序添加模式,
我的代码是这样的:
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没有得到任何日志数据。
最佳答案
您不想具有相同名称的追加程序。我相信您想要做的就是给您的附加程序赋予不同的名称,然后根据需要应用转换模式。如果需要,可以使用通用模式定义变量。因此,类似:
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', ...]
}
关于grails - Grails-如何将日志模式添加到文件追加器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23882690/