简体   繁体   English

如何在日志文件中打印堆栈跟踪

[英]How to print stack trace in log file

I am loging error im my java swing application: logger.error("ERROR: " + ex);我在我的 java swing 应用程序中记录错误: logger.error("ERROR: " + ex); where ex is exception其中 ex 是例外

this just print me 13:33:58,964 ERROR PlayOffPanel:292 - ERROR: java.lang.NullPointerException这只是打印我13:33:58,964 ERROR PlayOffPanel:292 - ERROR: java.lang.NullPointerException

but I wanna know stacktrace.但我想知道堆栈跟踪。

my log4j properites:我的 log4j 属性:

log4j.rootLogger=DEBUG,file

log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.maxFileSize=100KB
log4j.appender.file.maxBackupIndex=5
log4j.appender.file.File=error.log
log4j.appender.file.threshold=DEBUG
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

You have to write你必须写

logger.error("Error description",ex);

Look at the javadoc , the exception must be the second arguments if you want stacktrace.看看javadoc ,如果你想要堆栈跟踪,异常必须是第二个 arguments 。

Typically, you can pass the Throwable instance to the logger as well, eg通常,您也可以将Throwable实例传递给记录器,例如

logger.error( "My custom message", exception )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM