Grails Log4J tries to enter separate files for only one controller

I would like to log messages from one controller in my grails application at the information level to a specific file. Everything else in the information or at any other level should go to another default log file.

However, I cannot get log4J to populate the usage.log file at all, although it is happily written to the "default" list below.

Can someone tell me why my installation does not work?

My log4j installation looks like this:

 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 was able to solve this problem by replacing the class mapping of a specific controller with

 info usage: 'usage', additivity: true 

and then using

 private static final log = LogFactory.getLog("usage") 

No other documented or described method works, and ideally I can configure it based on a package or class, but it works.

+7
source share
1 answer

You need to be careful with named parameter types, which info et. and others hopes. The following configurations work in the Grails 2.1.1 test project:

 // log4j configuration log4j = { appenders { def logPattern = '%d{dd-MM-yyyy HH:mm:ss,SSS} %5p %c{2} - %m%n' console name: 'stdout', layout: pattern(conversionPattern: logPattern) appender new DailyRollingFileAppender( name: 'usage', datePattern: "'.'yyyy-MM-dd", layout: pattern(conversionPattern: logPattern), file: 'usage.log' ) } root { error 'stdout' } info additivity: false, usage: ["grails.app.controllers.com.example.MyController"] } 
+2
source

All Articles