使用 grails.config.locations 在 Grails 生产环境中配置 Log4j
我试图在生产环境中将 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)
...
我不明白为什么..有人吗?
谢谢。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
应该意味着运行 Tomcat 的用户在 Log4J 尝试创建 stacktrace.log 文件的文件夹中没有适当的写入权限。默认情况下, 这是 Tomcat 启动时的工作目录文件夹。
您可以使用
log4j.appender.stacktraces.File
配置选项 像这样: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:默认情况下,properties 文件(与任何其他未编译的资源一样)不会复制到WEB-INF/classes 文件夹中。
要手动复制它们,请在项目中创建文件 scripts/Events.groovy 并添加以下代码(假设您的 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):