使用 grails.config.locations 在 Grails 生产环境中配置 Log4j

发布于 2024-09-30 18:21:20 字数 2109 浏览 0 评论 0 原文

我试图在生产环境中将 log4j 配置维护在单独的文件中。我有这个 log4j.properties 文件(在生产中位于 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

我从 Config.groovy 中完全删除了 log4j 配置代码>.根据此评论中的第二个选项 http://jira.codehaus.org/browse/GRAILS-2730?focusedCommentId=137021&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_137021< /a> 我以这种方式在 Config.groovy 中添加了 log4j.properties 的位置:

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

但是在部署应用程序时,我仍然收到有关 stacktrace.log 的异常 文件:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

魂ガ小子 2024-10-07 18:21:20
java.io.FileNotFoundException: stacktrace.log (Permission denied)

应该意味着运行 Tomcat 的用户在 Log4J 尝试创建 stacktrace.log 文件的文件夹中没有适当的写入权限。默认情况下, 这是 Tomcat 启动时的工作目录文件夹。

您可以使用 log4j.appender.stacktraces.File 配置选项 像这样

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
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
想念有你 2024-10-07 18:21:20

默认情况下,properties 文件(与任何其他未编译的资源一样)不会复制到WEB-INF/classes 文件夹中。

要手动复制它们,请在项目中创建文件 scripts/Events.groovy 并添加以下代码(假设您的 properties 文件位于应用程序根目录中):

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

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")
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文