简体   繁体   中英

Configuring Grails Access Logging from run-app

Since calling run-app uses the tomcat-plugin in grails, how do I modify the grails AccessLogValve in the server.xml when it does not exists?

I only need this for development since in production I will just deploy the war to tomcat.

Thanks In Advance

You can configure it in a callback for the 'ConfigureTomcat' event in scripts/_Events.groovy:

import org.apache.catalina.valves.AccessLogValve

eventConfigureTomcat = { tomcat ->
 tomcat.host.addValve new AccessLogValve(
  directory: basedir, prefix: 'localhost_access_log.', pattern: 'common')
}

I had to wrap this in a dev environment block or I got horrible errors outside of dev

Here's what I ended up with, but I'm still not happy with it, as

grails run-war -https

isn't happy

eventConfigureTomcat = { tomcat ->
    if (grailsEnv == "development") {
        tomcat?.host?.addValve new AccessLogValve(
            directory: basedir,
            prefix: 'localhost_access_log.',
            suffix: '.log',
            pattern: 'common')
    }
}

produces this:

[unzip] Expanding: foo.war into /Users/tak/.grails/1.3.7/projects/foo/war
Running Grails application..
java.lang.NullPointerException: Cannot set property 'hostname' on null object
at org.grails.tomcat.TomcatServer.startSecure(TomcatServer.groovy:273)

sadness.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM