views:

4825

answers:

5

hi,

I have this log4j configuration in my grails config.groovy

log4j = {
    error  'org.codehaus.groovy.grails.web.servlet',  //  controllers
                   'org.codehaus.groovy.grails.web.pages' //  GSP
    warn 'org.mortbay.log' 


    appenders {
        rollingFile  name:'infoLog', file:'info.log', threshold: org.apache.log4j.Level.INFO, maxFileSize:1024
        rollingFile  name:'warnLog', file:'warn.log', threshold: org.apache.log4j.Level.WARN, maxFileSize:1024
        rollingFile  name:'errorLog', file:'error.log', threshold: org.apache.log4j.Level.ERROR, maxFileSize:1024
        rollingFile  name:'custom', file:'custom.log', maxFileSize:1024
    }

    root {
        info 'infoLog','warnLog','errorLog','custom', stdout
        error()
        additivity = true
    }
}

the infoLog,warnLog and errorLog was from the previous question ... they were working well.

now I add new RollingFile wit name "custom" ...

I tried to log from my controller and service using log.info("something .... ${obj}"); but it seems that message was not inserted into custom.log, do I need to add something to the configuration ?

thank you !!

+2  A: 

just got answer from the grails' mailing list:

i just need to add

debug "grails.app"

bellow warn "org.mortbay.log"

case closed ! :)

nightingale2k1
even if i use a custom appender it always ends up in the root appender as well. And if i remove my appender from the root then it does not work at all. Any way to prevent that from happening?
Bharani
A: 

How to find the log file? thanks

in development with jetty i found it in the root folder. i haven't test on the server such as glas fish.
nightingale2k1
A: 

I have a log4j properties in Config.groovy. log4j = {

        grails.serverURL = "http://localhost:8080/${appName}"
        def catalinaBase = System.properties.getProperty('catalina.base')
        if (!catalinaBase) catalinaBase = '.'   // just in case
        def logDirectory = "${catalinaBase}/logs"

        appenders {
            appender new org.apache.log4j.DailyRollingFileAppender(name: "friendsJob", datePattern: "'.'yyyy-MM-dd", file: "${logDirectory}/Sg/friends/friendsJob.txt", layout: pattern(conversionPattern: '[%d{yyyy-MM-dd hh:mm:ss.SSS}] %p %c{5} %m%n'))
            appender new org.apache.log4j.DailyRollingFileAppender(name: "followerJob", datePattern: "'.'yyyy-MM-dd", file: "${logDirectory}/Sg/follower/followerJob.txt", layout: pattern(conversionPattern: '[%d{yyyy-MM-dd hh:mm:ss.SSS}] %p %c{5} %m%n'))
            appender new org.apache.log4j.DailyRollingFileAppender(name: "mentionJob", datePattern: "'.'yyyy-MM-dd", file: "${logDirectory}/Sg/mention/mentionJob.txt", layout: pattern(conversionPattern: '[%d{yyyy-MM-dd hh:mm:ss.SSS}] %p %c{5} %m%n'))
            appender new org.apache.log4j.DailyRollingFileAppender(name: "autoFollowJob", datePattern: "'.'yyyy-MM-dd", file: "${logDirectory}/Sg/autofollow/autoFollowJob.txt", layout: pattern(conversionPattern: '[%d{yyyy-MM-dd hh:mm:ss.SSS}] %p %c{5} %m%n'))
            appender new org.apache.log4j.DailyRollingFileAppender(name: "retweetJob", datePattern: "'.'yyyy-MM-dd", file: "${logDirectory}/Sg/retweet/retweetJob.txt", layout: pattern(conversionPattern: '[%d{yyyy-MM-dd hh:mm:ss.SSS}] %p %c{5} %m%n'))
            appender new org.apache.log4j.DailyRollingFileAppender(name: "profileUpdateJob", datePattern: "'.'yyyy-MM-dd", file: "${logDirectory}/Sg/profileUpdate/profileUpdateJob.txt", layout: pattern(conversionPattern: '[%d{yyyy-MM-dd hh:mm:ss.SSS}] %p %c{5} %m%n'))
            appender new org.apache.log4j.DailyRollingFileAppender(name: "searchJob", datePattern: "'.'yyyy-MM-dd", file: "${logDirectory}/Sg/Search/searchJob.txt", layout: pattern(conversionPattern: '[%d{yyyy-MM-dd hh:mm:ss.SSS}] %p %c{5} %m%n'))
            appender new org.apache.log4j.DailyRollingFileAppender(name: "appLog",datePattern: "'.'yyyy-MM-dd", file: "${logDirectory}/Sg/AppLog/appLog.log", layout: pattern(conversionPattern: '[%d{yyyy-MM-dd hh:mm:ss.SSS}] %p %c{5} %m%n'))
        }
        info friendsJob: 'grails.app.task.twitter.FriendsListJob'
        info followerJob: 'grails.app.task.twitter.FollowersListJob'
        info mentionJob: 'grails.app.task.twitter.MentionJob'
        info autoFollowJob: 'grails.app.task.twitter.AutoFollowJob'
        info retweetJob: 'grails.app.task.twitter.RetweetsJob'
        info profileUpdateJob: 'grails.app.task.twitter.ProfileUpdateJob'
        info searchJob: 'grails.app.task.twitter.SearchJob'
        info appLog: 'grails.app.controller.SocialApiController'
        info appLog: 'grails.app.service'
        info appLog: 'grails.app.commons'
        info appLog: 'grails.app.jsontwitter'
        info appLog: 'grails.app.tagLib'
        info appLog: 'grails.app.domain'

}

its work when i run the application from Intellij using Jetty. But when i create the war file and deploy to tomcat log files are created but no log generted.

Can some one help me. Where the log4j.properties file created in war. I also add my separate log4j.property file in /WEB-INF/lib/grails-core also. but of no use.

Hasham Habib
A: 

I have exact the same jetty/tomcat env's. Spent hours to figure it out. The trick is to define the file location (a relative path in my case) as a global variable inside Config.groovy, customized it in the environment blocks, and use the variable location inside log4j closure. Sample code is at: http://denistek.blogspot.com/2010/02/grails-environment-specific-logging-to.html

Denis Wang
A: 

please see Log4j: How to write to a specific appender?

Ford Guo