Grails:将堆栈跟踪记录到标准输出

标签 grails grails-2.0

当我启动 grails 应用程序时,出现以下错误:

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



我知道这可以通过 chowning 一些文件/目录或通过更改日志转到的文件来解决,但我不希望这样:我只想将 stracktraces 记录到 stdout。

documentation状态:

For example if you prefer full stack traces to go to the console, add this entry:

error stdout: "StackTrace"



然而:它还指出:

This won't stop Grails from attempting to create the stacktrace.log file - it just redirects where stack traces are written to.



然后:

or, if you don't want to the 'stacktrace' appender at all, configure it as a 'null' appender:


log4j = {
    appenders {
        'null' name: "stacktrace"
    }
}

我结合了 2 并获得以下配置:
// log4j configuration
environments {
    production {
        log4j = {
            appenders {
                console name:'stdout', layout:pattern(conversionPattern: '%c{2} %m%n')
                // Don't use stacktrace.log
                'null' name: "stacktrace"
            }
        }

    }
}

log4j = {
    // print the stacktrace to stdout
    error stdout:"StackTrace"
}

不幸的是,这不起作用:

INFO: Deploying web application archive MyBackend.war

Sep 12, 2012 4:46:11 PM org.apache.catalina.core.StandardContext start

SEVERE: Error listenerStart

Sep 12, 2012 4:46:11 PM org.apache.catalina.core.StandardContext start

SEVERE: Context [/MyBackend2] startup failed due to previous errors



诚然,它不再尝试写入 stacktrace.log,因此不再抛出 Permission denied 错误,但我不知道为什么该应用程序无法启动,因为它记录的唯一内容是“Error listenerStart”

任何人都可以帮我配置我的应用程序以将堆栈跟踪记录到标准输出吗?

最佳答案

Grails 错误报告:
http://jira.grails.org/browse/GRAILS-2730
(包含一些解决方法)

如果您希望堆栈跟踪到标准输出:

log4j = {
  appenders {
    console name:'stacktrace'
    ...
  }
...
}

禁用 stacktrace.log:
log4j = {
  appenders {
    'null' name:'stacktrace'
    ...
  }
...
}

Tomcat 日志目录中特定于应用程序的日志文件的堆栈跟踪
log4j = {
  appenders {
    rollingFile name:'stacktrace', maxFileSize:"5MB", maxBackupIndex: 10, file:"${System.getProperty('catalina.home')}/logs/${appName}_stacktrace.log", 'append':true, threshold:org.apache.log4j.Level.ALL
    ...
  }
...
}

感谢这篇博文:http://haxx.sinequanon.net/2008/09/grails-stacktracelog/

关于Grails:将堆栈跟踪记录到标准输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12393020/

相关文章:

mysql - 列的字符串值不正确

Grails在jar中找不到类

spring - 错误dynamiccontroller.DynamicControllerManager [Grails]

grails - 从 grails 插件访问日志

grails 2.1.0 链式选择关系

grails - 使用下拉列表的出生日期

json - Grails Json Views "model"键与模型关键字冲突

grails - 如何有条件地禁用表单输入字段

javascript - 如何在grails的safari浏览器中通过ajax提交表单

grails - groovy的属性在grails3中不起作用