我想根据模块登录到不同的appender ......
我有3个appender:控制台,用于记录控制器和服务的滚动文件,以及用于记录作业中某些内容的另一个滚动文件。我想仅为其滚动文件记录作业的代码,并仅使用其他滚动文件记录控制器和服务。
所以这是我的grails log4j配置:
development {
def catalinaBase = System.properties.getProperty('catalina.base')
if (!catalinaBase) catalinaBase = '.'
def logDirectory = "${catalinaBase}/logs/AmbienticWebsite"
log4j = {
appenders {
console name:'stdout', layout:pattern(conversionPattern: '%c{2} [%p] - %m%n')
appender new DailyRollingFileAppender(
name: "rollingFileGrailsApp",
file: "${logDirectory}/GrailsApp.log",
datePattern: "'.'yyyy-MM-dd",
layout: pattern(conversionPattern: commonPattern)
)
appender new DailyRollingFileAppender(
name: "rollingFileImport",
file: "${logDirectory}/Imports.log",
datePattern: "'.'yyyy-MM-dd",
layout: pattern(conversionPattern: commonPattern)
)
}
root {
error 'stdout', 'rollingFileImport', 'rollingFileGrailsApp' // both stdout and AmbienticWebsite_dev.log are filled by logging information
additivity = false
}
debug rollingFileImport: 'ambienticwebsite.EventImportJob',
'time2marketing.time2marketingImportService',
'eventImportData.DiscomImportDataService',
'eventImportData.EventImportService'
info rollingFileGrailsApp: 'ambienticwebsite',
'ambienticwebsite.jobManagement.AmbienticJobListener',
'BootStrap',
'grails.app.controllers',
'grails.app.services'
}
}
使用此配置,日志将写入两个滚动文件和stdout。如果我从根目录中删除滚动appender,则即使为文件组指定了appender,滚动文件也会保持为空。
有没有人建议将日志分成appender?
答案 0 :(得分:1)
我认为您需要将additivity: false
添加到自定义附加程序。
debug rollingFileImport: [foo, bar, baz]
additivity: false
info rollingFileGrailsApp: [foo1, bar1, baz1]
additivity: false
请参阅grails中的Logger Inheritance。