user3773712
user3773712

Reputation: 173

grails log4j is not working on custom appenders

I am trying to log the "info and above level" logging from grails.app.controllers and grails.app.services into this appender "appLog". From the documentation and a lot of google search and ofcourse stack overflow. I understood that all i need is my appender and then logger info. But that never works for me, so i added the root block as below and made it route every log to my appender and I also set my additivity to false so that it won't pull any of the inherited logs. My requirement was very simple, but i could not get it working. I am using grails 2.4.1.

Can someone please shed some light on what is going wrong here?

Below is my configuration:

Log4j:main{
    appender name: "appLog",
        new org.apache.log4j.DailyRollingFileAppender(
            threshold: org.apache.log4j.Level.INFO,
            datePattern: "'.'yyyy-MM-dd",
            file: log4jFileName,
            layout: pattern(conversionPattern: '[%d{yyyy-MM-dd hh:mm:ss.SSS}] %p %c{5} %m%n')
        )

    info additivity: false, appLog: "grails.app.services.xxxService"

    root {
        debug 'appLog'
        additivity = false 
    }

}

Upvotes: 0

Views: 1131

Answers (1)

grantmcconnaughey
grantmcconnaughey

Reputation: 10689

A couple things I'm seeing wrong here:

  1. Your name: "appLog" portion should be inside of the DailyRollingFileAppender constructor.
  2. You are missing an appenders block.

Try changing the configuration to this:

log4j = {
    appenders {
        appender new org.apache.log4j.DailyRollingFileAppender(
            name: "appLog",
            threshold: org.apache.log4j.Level.INFO,
            datePattern: "'.'yyyy-MM-dd",
            file: log4jFileName,
            layout: pattern(conversionPattern: '[%d{yyyy-MM-dd hh:mm:ss.SSS}] %p %c{5} %m%n')
        )
    }

    info additivity: false,
         appLog: "grails.app.services.xxxService"

    root {
        debug 'appLog'
    }
}

Upvotes: 1

Related Questions