log4j in grails : how to log into file?

孤街浪徒 提交于 2019-12-21 04:37:14

问题


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 !!


回答1:


just got answer from the grails' mailing list:

i just need to add

debug "grails.app"

bellow warn "org.mortbay.log"

case closed ! :)




回答2:


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




回答3:


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

After all the solution is to put the additivity setting to the package configuration:

info specialLog:'activityLog', additivity:false



来源:https://stackoverflow.com/questions/1157159/log4j-in-grails-how-to-log-into-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!