根据文件grails log4j diffrerent appenders [英] grails log4j diffrerent appenders according files
问题描述
我想根据模块记录到不同的appender ...
我有3个appender:控制台,用于记录控制器和服务的滚动文件,另一个滚动文件记录一些工作中的东西。我只想为其滚动文件记录作业的代码,并仅使用其他滚动文件记录控制器和服务。
所以这是我的grails log4j配置:
开发{
def catalinaBase = System.properties.getProperty('catalina.base')
如果(!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 {
错误'stdout','rollingFileImport','rollingFileGrailsApp'// stdout和AmbienticWebsite_dev.log都被记录信息
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,滚动文件也会保持为空。
有没有人有建议将登录appenders?
我想你需要添加 additivity:false $ c $
debug rollingFileImport:[foo,bar,baz]
additivity:false
info rollingFileGrailsApp:[foo1,bar1,baz1]
additivity:false
请参阅grails中的记录器继承。
I would like to log to different appenders depending on the module...
I have 3 appenders: the console, a rolling file to log the controller and services, and another rolling file to log some stuff in jobs. I want to log the code of the job only for its rolling file and to log the controllers and services only with the other rolling file.
So this is my grails log4j configuration:
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'
}
}
With this configuration, the logs are written to the two rolling files and stdout. If I delete the rolling appenders from the root, the rolling file stays empty, even if the appenders are specified for the group of files.
Does anyone have advice to separate the log into the appenders?
I think you need to add additivity: false
to the custom appenders.
debug rollingFileImport: [foo, bar, baz]
additivity: false
info rollingFileGrailsApp: [foo1, bar1, baz1]
additivity: false
Refer Logger Inheritance in grails.
这篇关于根据文件grails log4j diffrerent appenders的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!