Grails:将堆栈跟踪记录到标准输出 [英] Grails: log stacktrace to stdout

查看:117
本文介绍了Grails:将堆栈跟踪记录到标准输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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


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


我知道这可以通过chowning一些文件/目录或通过更改日志文件来解决,但我不' t想要这个:我只想stracktraces被记录到标准输出。



documentation 指出:


例如,如果您更喜欢全堆栈跟踪转到控制台,添加
这个条目:

错误stdout:StackTrace

但是:它也表示:


这不会阻止Grails尝试创建stacktrace.log
文件 - 它只是重定向堆栈跟踪的地方。


后来:


或者,如果您根本不想使用'stacktrace'appender,请将
配置为'null'appender:




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

我将2合并并获得以下配置:

  // log4j配置
环境{
生产{
log4j = {
appenders {
控制台名称:'stdout',布局:pattern(conversionPattern:'%c {2}%m%n')
//不要使用stacktrace.log
'null'name:stacktrace
}
}

}
}

log4j = {
//打印堆栈跟踪到标准输出
错误标准输出:StackTrace

不幸的是,这是行不通的:


信息:部署Web应用程序存档我的Backend.war



2012年9月12日下午4:46:11 org.apache.catalina.core.StandardContext开始



SEVERE:Error listenerStart



2012年9月12日下午4:46:11 org.apache.catalina.core.StandardContext start



SEVERE:Context [/ MyBackend2]启动因以前的错误而失败


无可否认,再次写stacktrace.log,所以Permission拒绝错误不再被抛出,但我不知道为什么应用程序不会启动,因为它记录的唯一东西是Error listenerStart。



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

解决方案

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

如果你想要堆栈跟踪到标准输出:

  log4j = { 
appenders {
控制台名称:'stacktrace'
...
}
...
}

禁用stacktrace.log:

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

stacktraces到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/

When I launch my grails application, I get the following error:

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

I know this can be solved by chowning some files/directories or by changing the file the logs go to, but I don't want this: I just want stracktraces to be logged to the stdout.

The documentation states:

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

error stdout: "StackTrace"

However: it also states:

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

And later:

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

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

I combine the 2 and get the following configuration:

// 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"
}

Unfortunately, this doesn't work:

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

Admittedly, it doesn't attempt to write stacktrace.log anymore, so the Permission denied error isn't thrown anymore, but I have no clue why the app won't start becaue the only thing it logs is "Error listenerStart"

Can anyone please help me with configuring my app to just log the stacktraces to stdout?

解决方案

Grails Bug report: http://jira.grails.org/browse/GRAILS-2730 (contains some workarounds)

If you want stacktraces to stdout:

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

Disable stacktrace.log:

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

stacktraces to application specific log file in Tomcat logs directory

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

kudos to this blog post: http://haxx.sinequanon.net/2008/09/grails-stacktracelog/

这篇关于Grails:将堆栈跟踪记录到标准输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆