尝试使用 logback 打印堆栈跟踪,但未打印堆栈跟踪
Tried to print stack trace using logback but stack trace is not printing
我正在使用以下代码来打印 try catch 块中发生的任何异常,但是当发生异常时,logback 不会打印完整的堆栈跟踪,而是写入,一行错误(它不会清楚地说出是什么原因造成的。如何在 logback 输出中打印出完整的堆栈跟踪?
捕获异常的try catch块
try {
// Create JMS objects
context = cf.createContext();
destination = context.createQueue("queue:///" + QUEUE_NAME);
((MQDestination)destination).setTargetClient(JMSC.MQJMS_CLIENT_NONJMS_MQ);
} catch (Exception e) {
// catch any exception occurred while trying to connect to the destination queue Manager
e.printStackTrace();
LOGGER.info(e.toString());
return "Unable to connect to the destination queue Manager '"+QMGR +"'";
}
重新登录错误输出:
21:18:10.748 [http-nio-8010-exec-4] INFO com.mqMessageHandler.Webcontroller - com.ibm.msg.client.jms.DetailedJMSRuntimeException: JMSWMQ0018: Failed to connect to queue manager 'KAU.TST' with connection mode 'Client' and host name '192.168.1.25(1540)'.
Check the queue manager is started and if running in client mode, check there is a listener running. Please see the linked exception for more information.
e.toString()
只会打印错误信息。
如果要打印完整的堆栈跟踪,请使用错误方法:
LOGGER.error("Exception occurred",e)
如果您需要提取完整的堆栈跟踪,请从 apache common 检查以下 util 方法:
LOGGER.info("Exception : ",ExceptionUtils.getStackTrace(e));
我正在使用以下代码来打印 try catch 块中发生的任何异常,但是当发生异常时,logback 不会打印完整的堆栈跟踪,而是写入,一行错误(它不会清楚地说出是什么原因造成的。如何在 logback 输出中打印出完整的堆栈跟踪?
捕获异常的try catch块
try {
// Create JMS objects
context = cf.createContext();
destination = context.createQueue("queue:///" + QUEUE_NAME);
((MQDestination)destination).setTargetClient(JMSC.MQJMS_CLIENT_NONJMS_MQ);
} catch (Exception e) {
// catch any exception occurred while trying to connect to the destination queue Manager
e.printStackTrace();
LOGGER.info(e.toString());
return "Unable to connect to the destination queue Manager '"+QMGR +"'";
}
重新登录错误输出:
21:18:10.748 [http-nio-8010-exec-4] INFO com.mqMessageHandler.Webcontroller - com.ibm.msg.client.jms.DetailedJMSRuntimeException: JMSWMQ0018: Failed to connect to queue manager 'KAU.TST' with connection mode 'Client' and host name '192.168.1.25(1540)'.
Check the queue manager is started and if running in client mode, check there is a listener running. Please see the linked exception for more information.
e.toString()
只会打印错误信息。
如果要打印完整的堆栈跟踪,请使用错误方法:
LOGGER.error("Exception occurred",e)
如果您需要提取完整的堆栈跟踪,请从 apache common 检查以下 util 方法:
LOGGER.info("Exception : ",ExceptionUtils.getStackTrace(e));