我使用下面的代码来打印try catch块中发生的任何异常,但是当异常发生时,logback并不会打印完整的堆栈跟踪,而是只会写入一行错误(这不能清楚地说明是什么导致的)。如何在logback输出中打印出完整的堆栈跟踪?
尝试捕捉异常的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.
发布于 2022-04-15 22:18:52
e.toString()
将只打印错误消息。
如果要打印完整的堆栈跟踪,请使用错误方法:
LOGGER.error("Exception occurred",e)
如果需要提取完整的堆栈跟踪,请从ApacheCommon中签出以下util方法:
LOGGER.info("Exception : ",ExceptionUtils.getStackTrace(e));
https://stackoverflow.com/questions/71888635
复制相似问题