如何在 JAVA 中查看完整的异常日志?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12226375/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 08:07:01  来源:igfitidea点击:

How can I see a full log of exceptions in JAVA?

javaexception-logging

提问by aqjune

When I run some java program with a command java ExceptionTest, exceptions are sometimes omitted and looks like

当我使用命令java ExceptionTest运行一些 java 程序时,有时会忽略异常,看起来像

Exception in thread "main" java.lang.NoClassDefFoundError: aa/bb/DD
        at SOMEWHERE(unknown source)
Caused by: java.lang.ClassNotFoundException: aaa.bbb.CC
        at SOMEWHER(unknown source)
        ... 13 more

I'd like to see 13 more exceptions in this case. Is there an option to see all exception log?

在这种情况下,我想再看到 13 个例外。是否可以选择查看所有异常日志?

回答by Tomasz Nurkiewicz

You already see them, it's only the ridiculous way Java (and Logback by defaul) prints exceptions by default. This stack trace:

您已经看到了它们,这只是 Java(默认情况下为 Logback)打印异常的荒谬方式。此堆栈跟踪:

Exception in thread "main" java.lang.NoClassDefFoundError: aa/bb/DD
        at SOMEWHERE(unknown source)
Caused by: java.lang.ClassNotFoundException: aaa.bbb.CC
        at SOMEWHER(unknown source)
        ... 13 more

actually means the following program flow (from bottom to top):

实际上意味着以下程序流程(从下到上):

Caused by: java.lang.ClassNotFoundException: aaa.bbb.CC
        at SOMEWHER(unknown source)
Exception in thread "main" java.lang.NoClassDefFoundError: aa/bb/DD
        at SOMEWHERE(unknown source)

The ... 13 more(N common frames omittedin Logback) only means that these exceptions were already printed before. In Logback you can restructure stack track to avoid duplicates and print stack lines always in correct order, see my blog.

... 13 moreN common frames omitted在的logback)仅意味着这些例外情况,之前已经打印。在 Logback 中,您可以重构堆栈轨道以避免重复并始终以正确的顺序打印堆栈行,请参阅我的博客

回答by Jens Schauder

there aren't 13 more exceptions. There are 13 more lines to the call stack which are identical to previous call stacks, as described here: http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Throwable.html#printStackTrace()

没有另外 13 个例外。调用堆栈还有 13 行与之前的调用堆栈相同,如下所述:http: //java.sun.com/j2se/1.5.0/docs/api/java/lang/Throwable.html#printStackTrace()