开发者

Log4j configuration in Grails production environment with grails.config.locations

开发者 https://www.devze.com 2023-01-23 11:25 出处:网络
I amtrying to maintain the log4j configuration in a separate file in production environment. I have this log4j.properties file (which in production resides in WEB-INF/classes):

I am trying to maintain the log4j configuration in a separate file in production environment. I have this log4j.properties file (which in production resides in WEB-INF/classes):

log4j.rootLogger=error, stdout
log4j.rootLogger.additivity=false
log4j.logger.grails.app=info, stdout
log4j.additivity.grails.app=false
log4j.additivity.grails.app.service=false
log4j.logger.grails.app.controller=debug, stdout
log4j.additivity.grails.app.controller=false
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d [%7r] %6p - %14.14c - %m%n

I completely removed the log4j configuration from the Config.groovy. And according to the second option in this comment http://jira.codehaus.org/browse/GRAILS-2730?focusedCommentId=137021&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_137021 I added the location of log4j.properties in Config.groovy this way:

  production {
    grails.serverURL = "http://xxxxx.ru/${appName}"
    grails.config.locations = [ "classpath:log4j.properties" ]
  }

But when deploying the application I still get the exception about the stacktrace.log file:

log4j:ERROR setFile(null,true) call failed.
java.io.FileNotFoundException: stacktrace.log (Permission denied)
    at java.io.FileOutputStream.openAppend(Native Method)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:207)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:131)
    at org.apache.log4j.FileAppender.setFile(FileAppender.java:294)
    at org.apache.log4j.FileAppender.activateOptions(FileAppender.java:165)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun开发者_开发百科.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
...

I do not understand why.. Anyone?

Thanks.


java.io.FileNotFoundException: stacktrace.log (Permission denied)

should mean that the user that Tomcat is running under does not have proper write permissions in the folder where Log4J tries to create the stacktrace.log file. By default, this is the folder that had been the working directory when Tomcat had been started.

You can specify a custom stacktrace.log location with the log4j.appender.stacktraces.File configuration option, like so:

log4j.logger.stacktraces.com.foo=INFO,stacktraces
log4j.additivity.stacktraces=false
log4j.appender.stacktraces=org.apache.log4j.DailyRollingFileAppender
log4j.appender.stacktraces.File=${log.dir}/fooStacktraces.log
log4j.appender.stacktraces.DatePattern=${roll.pattern.daily}
log4j.appender.stacktraces.layout=org.apache.log4j.PatternLayout
log4j.appender.stacktraces.layout.ConversionPattern=%d{${datestamp}}%p%m%n


By default, properties files (like any other resources that are not compiled) are not copied to the WEB-INF/classes folder.

To copy them, manually, create the file scripts/Events.groovy in your project and add the following code (assuming that your properties file is in the application root):

eventCompileEnd = {
    ant.copy(todir:classesDirPath) {
        fileset(file:"${basedir}/*.properties")
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消