使用Log4CXX_ERROR我只能打印e.what()。
catch (const std::exception e)
{
logger->error("exception:" << e.what());
//logger->error("exception:" << e); //not allowed
}
如何使用log4cxx打印异常堆栈跟踪?
答案 0 :(得分:1)
首先添加处理函数:
void trace() {
void *array[20];
size_t size;
/* store up to 20 return address of the current program state in array
and return the exact number of values stored */
size = (size_t)backtrace(array, 20);
/* return names of functions from the backtrace list in array and
write result immediately to stderr */
backtrace_symbols_fd(array, size, STDERR_FILENO);
}
然后调用此函数在stderr上转储堆栈跟踪。