I would like to log messages from one controller in my grails application at info level to a specific file. Everything else at info or any other level should go to another default logging file.
However, I cannot get log4J to populate the usage.log file at all, although it happily logs to the 'default' appender defined below.
Can anyone give any clues as to why my setup is not working?
My log4j setup is as follows:
log4j = {
appenders {
console name: 'stdout',
layout: pattern(conversionPattern: '%d %-5p %c{1} - %m%n')
appender new DailyRollingFileAppender(
name: 'default',
datePattern: "'.'yyyy-MM-dd",
layout: pattern(conversionPattern: '%d %-5p %c{1} - %m%n'),
file: 'C:/logs/default.log'
)
//daily usage log
appender new DailyRollingFileAppender(
name: 'usage', datePattern: "'.'yyyy-MM-dd",
layout: pattern(conversionPattern: '%d %-5p %c{1} - %m%n'),
file: 'C:/logs/usage.log'
)
}
info usage: "grails.app.controllers.com.example.MyController",
additivity: false
root {
info 'stdout', 'default'
additivity = true
}
info 'grails.app'
}
UPDATE
I have been able to solve this by replacing the specific controller class mapping with
info usage: 'usage', additivity: true
and then using
private static final log = LogFactory.getLog("usage")
No other documented or described way seems to work, and ideally I'd be able to configure it on a package or class basis, but this works.
grails.app.controllers....one after thegrails.appone). What version of Grails are you using? - Ian Robertslog4jclosure in anenvironmentsblock or an external config file. - Ian RobertsSystem.out.println(log.name)into an action of your controller, to confirm that it's using the logger you think it's using. - Ian Roberts