Grails Logging not working in Forked Mode

2019-07-23 07:15发布

问题:

I'm having a problem where logging works correctly when I run tomcat in non-forked mode from grails, but does not work correctly in forked mode.

Here is my Log4j configuration:

Config.groovy:

// log4j configuration
log4j = {

appenders {
    file name:"fileLogger", file: "c:/logs/app-log.log", threshold: Level.DEBUG
}

debug fileLogger: ['com.foo', 'BootStrap']

info  fileLogger: ['org.springframework']

error fileLogger: [
        'org.codehaus.groovy.grails.web.servlet',        // controllers
        'org.codehaus.groovy.grails.web.pages',          // GSP
        'org.codehaus.groovy.grails.web.sitemesh',       // layouts
        'org.codehaus.groovy.grails.web.mapping.filter', // URL mapping
        'org.codehaus.groovy.grails.web.mapping',        // URL mapping
        'org.codehaus.groovy.grails.commons',            // core / classloading
        'org.codehaus.groovy.grails.plugins',            // plugins
        'org.codehaus.groovy.grails.orm.hibernate',      // hibernate integration
        'org.hibernate',
        'net.sf.ehcache.hibernate']
}

When I run grails run-app, the log file is correcly populated.

However, when I change my BuildConfig.groovy file to run tomcat in forked mode:

BuildConfig.groovy:

grails.project.fork = [
    run: [maxMemory:1024, minMemory:64, debug:false, maxPerm:256]
]

The log file does not get populated.

Is there something wrong with my configuration? Why would it work in one mode, but not the other?

回答1:

You have the threshold for the appender set to DEBUG level. I think in the forked tomcat mode the default level is set to INFO. In order to make it work for the forked mode you might need to increase the logging level to INFO and change DEBUGs to INFOs.

info fileLogger: ['org.springframework', 'com.foo', 'BootStrap']