开发者

BasicConfigurator doesn't log stack traces by default in JUnit Tests

In running some JUnit tests I start with the following to se开发者_StackOverflow中文版t up Log4J:

BasicConfigurator.configure()

I'm then calling the following via Commons Logging:

LogFactory.getLogger(this.getClass()).fatal(exception)

This doesn't print stack traces though (only the exception message).

I need to know what steps are necessary to print stack traces via the simplified logging setup used in JUnit tests? I would prefer not to have to fully configure Log4J just for JUnit tests, but if I must, let me know.


This is nothing to do with the logger configurations.

Read the javadoc for the fatal(Object) method. It says:

"WARNING Note that passing a Throwable to this method will print the name of the Throwable but no stack trace. To print a stack trace use the fatal(Object, Throwable) form instead."

If you want the logs to include a stacktrace, you must use the 2 argument version of the method. This applies to the corresponding methods for other log levels as well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜