Add log_exc_printf() with stack trace
This commit is contained in:
+3
-3
@@ -568,7 +568,7 @@ void Context::Pvt::onSearchS(evutil_socket_t fd, short evt, void *raw)
|
||||
for(unsigned i=0; i<4 && static_cast<Pvt*>(raw)->onSearch(); i++) {}
|
||||
|
||||
}catch(std::exception& e){
|
||||
log_crit_printf(io, "Unhandled error in search Rx callback: %s\n", e.what());
|
||||
log_exc_printf(io, "Unhandled error in search Rx callback: %s\n", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -693,7 +693,7 @@ void Context::Pvt::tickSearchS(evutil_socket_t fd, short evt, void *raw)
|
||||
try {
|
||||
static_cast<Pvt*>(raw)->tickSearch();
|
||||
}catch(std::exception& e){
|
||||
log_crit_printf(io, "Unhandled error in search timer callback: %s\n", e.what());
|
||||
log_exc_printf(io, "Unhandled error in search timer callback: %s\n", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -724,7 +724,7 @@ void Context::Pvt::tickBeaconCleanS(evutil_socket_t fd, short evt, void *raw)
|
||||
try {
|
||||
static_cast<Pvt*>(raw)->tickBeaconClean();
|
||||
}catch(std::exception& e){
|
||||
log_crit_printf(io, "Unhandled error in beacon cleaner timer callback: %s\n", e.what());
|
||||
log_exc_printf(io, "Unhandled error in beacon cleaner timer callback: %s\n", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -402,7 +402,7 @@ void Connection::tickEchoS(evutil_socket_t fd, short evt, void *raw)
|
||||
try {
|
||||
static_cast<Connection*>(raw)->tickEcho();
|
||||
}catch(std::exception& e){
|
||||
log_crit_printf(io, "Unhandled error in echo timer callback: %s\n", e.what());
|
||||
log_exc_printf(io, "Unhandled error in echo timer callback: %s\n", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -158,7 +158,7 @@ void Connection::handle_GET_FIELD()
|
||||
try {
|
||||
done(std::move(res));
|
||||
}catch(std::exception& e){
|
||||
log_err_printf(setup, "Unhandled exception %s in Info result() callback: %s\n", typeid (e).name(), e.what());
|
||||
log_exc_printf(setup, "Unhandled exception %s in Info result() callback: %s\n", typeid (e).name(), e.what());
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
+3
-3
@@ -84,7 +84,7 @@ struct SubscriptionImpl : public OperationBase, public Subscription
|
||||
try {
|
||||
event(*this);
|
||||
}catch(std::exception& e){
|
||||
log_err_printf(io, "Unhandled user exception in Monitor %s %s : %s\n",
|
||||
log_exc_printf(io, "Unhandled user exception in Monitor %s %s : %s\n",
|
||||
__func__, typeid (e).name(), e.what());
|
||||
}
|
||||
}
|
||||
@@ -312,8 +312,8 @@ struct SubscriptionImpl : public OperationBase, public Subscription
|
||||
try {
|
||||
static_cast<SubscriptionImpl*>(raw)->tickAck();
|
||||
}catch(std::exception& e) {
|
||||
log_crit_printf(io, "Unhandled exception in %s %s : %s\n",
|
||||
__func__, typeid (e).name(), e.what());
|
||||
log_exc_printf(io, "Unhandled exception in %s %s : %s\n",
|
||||
__func__, typeid (e).name(), e.what());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
+3
-3
@@ -219,7 +219,7 @@ void ConnBase::bevEventS(struct bufferevent *bev, short events, void *ptr)
|
||||
try {
|
||||
conn->bevEvent(events);
|
||||
}catch(std::exception& e){
|
||||
log_crit_printf(connsetup, "%s %s Unhandled error in bev event callback: %s\n", conn->peerLabel(), conn->peerName.c_str(), e.what());
|
||||
log_exc_printf(connsetup, "%s %s Unhandled error in bev event callback: %s\n", conn->peerLabel(), conn->peerName.c_str(), e.what());
|
||||
conn->cleanup();
|
||||
}
|
||||
}
|
||||
@@ -230,7 +230,7 @@ void ConnBase::bevReadS(struct bufferevent *bev, void *ptr)
|
||||
try {
|
||||
conn->bevRead();
|
||||
}catch(std::exception& e){
|
||||
log_crit_printf(connsetup, "%s %s Unhandled error in bev read callback: %s\n", conn->peerLabel(), conn->peerName.c_str(), e.what());
|
||||
log_exc_printf(connsetup, "%s %s Unhandled error in bev read callback: %s\n", conn->peerLabel(), conn->peerName.c_str(), e.what());
|
||||
conn->cleanup();
|
||||
}
|
||||
}
|
||||
@@ -241,7 +241,7 @@ void ConnBase::bevWriteS(struct bufferevent *bev, void *ptr)
|
||||
try {
|
||||
conn->bevWrite();
|
||||
}catch(std::exception& e){
|
||||
log_crit_printf(connsetup, "%s %s Unhandled error in bev write callback: %s\n", conn->peerLabel(), conn->peerName.c_str(), e.what());
|
||||
log_exc_printf(connsetup, "%s %s Unhandled error in bev write callback: %s\n", conn->peerLabel(), conn->peerName.c_str(), e.what());
|
||||
conn->cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -133,7 +133,7 @@ struct evbase::Pvt : public epicsThreadRunable
|
||||
log_printf(logerr, lvl, "Exit loop worker: %d for %p\n", ret, base.get());
|
||||
|
||||
}catch(std::exception& e){
|
||||
log_crit_printf(logerr, "Unhandled exception in event_base run : %s\n",
|
||||
log_exc_printf(logerr, "Unhandled exception in event_base run : %s\n",
|
||||
e.what());
|
||||
start_sync.trigger();
|
||||
}
|
||||
@@ -154,7 +154,7 @@ struct evbase::Pvt : public epicsThreadRunable
|
||||
Guard G(lock);
|
||||
*work.result = std::current_exception();
|
||||
} else {
|
||||
log_crit_printf(logerr, "Unhandled exception in event_base : %s : %s\n",
|
||||
log_exc_printf(logerr, "Unhandled exception in event_base : %s : %s\n",
|
||||
typeid(e).name(), e.what());
|
||||
}
|
||||
}
|
||||
@@ -169,7 +169,7 @@ struct evbase::Pvt : public epicsThreadRunable
|
||||
try {
|
||||
self->doWork();
|
||||
}catch(std::exception& e){
|
||||
log_crit_printf(logerr, "Unhandled error in doWorkS callback: %s\n", e.what());
|
||||
log_exc_printf(logerr, "Unhandled error in doWorkS callback: %s\n", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,9 @@
|
||||
#include <pvxs/log.h>
|
||||
|
||||
#include <envDefs.h>
|
||||
#include <dbDefs.h>
|
||||
#include <osiSock.h>
|
||||
#include <epicsStackTrace.h>
|
||||
#include <epicsString.h>
|
||||
#include <epicsAssert.h>
|
||||
#include <epicsStdio.h>
|
||||
@@ -65,6 +67,13 @@ const char* log_prefix(const char* name, Level lvl)
|
||||
return prefix;
|
||||
}
|
||||
|
||||
void log_stacktrace()
|
||||
{
|
||||
// stack traces can be long. flush to reduce truncation
|
||||
errlogFlush();
|
||||
epicsStackTrace();
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -51,6 +51,9 @@ namespace detail {
|
||||
PVXS_API
|
||||
const char* log_prefix(const char* name, Level lvl);
|
||||
|
||||
PVXS_API
|
||||
void log_stacktrace();
|
||||
|
||||
} // namespace detail
|
||||
|
||||
//! Define a new logger global.
|
||||
@@ -82,6 +85,13 @@ void xerrlogHexPrintf(const void *buf, size_t buflen);
|
||||
#define log_info_printf(LOGGER, ...) log_printf(LOGGER, ::pvxs::Level::Info, __VA_ARGS__)
|
||||
#define log_debug_printf(LOGGER, ...) log_printf(LOGGER, ::pvxs::Level::Debug, __VA_ARGS__)
|
||||
|
||||
#define log_exc_printf(LOGGER, FMT, ...) do{ \
|
||||
if((LOGGER).test(::pvxs::Level::Crit)) { \
|
||||
errlogPrintf("%s " FMT, ::pvxs::detail::log_prefix((LOGGER).name, ::pvxs::Level::Crit), __VA_ARGS__); \
|
||||
::pvxs::detail::log_stacktrace(); \
|
||||
} \
|
||||
}while(0)
|
||||
|
||||
#define log_hex_printf(LOGGER, LVL, BUF, BUFLEN, FMT, ...) do{ if((LOGGER).test(LVL)) { \
|
||||
xerrlogHexPrintf(BUF, BUFLEN); \
|
||||
errlogPrintf("%s " FMT, ::pvxs::detail::log_prefix((LOGGER).name, LVL), __VA_ARGS__); } \
|
||||
|
||||
+2
-2
@@ -441,7 +441,7 @@ void Server::Pvt::onSearch(const UDPManager::Search& msg)
|
||||
try {
|
||||
pair.second->onSearch(searchOp);
|
||||
}catch(std::exception& e){
|
||||
log_err_printf(serversetup, "Unhandled error in Source::onSearch for '%s' : %s\n",
|
||||
log_exc_printf(serversetup, "Unhandled error in Source::onSearch for '%s' : %s\n",
|
||||
pair.first.second.c_str(), e.what());
|
||||
}
|
||||
}
|
||||
@@ -554,7 +554,7 @@ void Server::Pvt::doBeaconsS(evutil_socket_t fd, short evt, void *raw)
|
||||
try {
|
||||
static_cast<Pvt*>(raw)->doBeacons(evt);
|
||||
}catch(std::exception& e){
|
||||
log_crit_printf(serverio, "Unhandled error in beacon timer callback: %s\n", e.what());
|
||||
log_exc_printf(serverio, "Unhandled error in beacon timer callback: %s\n", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -224,7 +224,7 @@ void ServerConn::handle_SEARCH()
|
||||
try {
|
||||
pair.second->onSearch(op);
|
||||
}catch(std::exception& e){
|
||||
log_err_printf(serversetup, "Unhandled error in Source::onSearch for '%s' : %s\n",
|
||||
log_exc_printf(serversetup, "Unhandled error in Source::onSearch for '%s' : %s\n",
|
||||
pair.first.second.c_str(), e.what());
|
||||
}
|
||||
}
|
||||
@@ -311,7 +311,7 @@ void ServerConn::handle_CREATE_CHANNEL()
|
||||
break;
|
||||
}
|
||||
}catch(std::exception& e){
|
||||
log_err_printf(connsetup, "Client %s Unhandled error in onCreate %s,%d %s : %s\n", peerName.c_str(),
|
||||
log_exc_printf(connsetup, "Client %s Unhandled error in onCreate %s,%d %s : %s\n", peerName.c_str(),
|
||||
pair.first.second.c_str(), pair.first.first,
|
||||
typeid(&e).name(), e.what());
|
||||
}
|
||||
|
||||
+1
-1
@@ -388,7 +388,7 @@ void ServIface::onConnS(struct evconnlistener *listener, evutil_socket_t sock, s
|
||||
auto conn(std::make_shared<ServerConn>(self, sock, peer, socklen));
|
||||
self->server->connections[conn.get()] = std::move(conn);
|
||||
}catch(std::exception& e){
|
||||
log_crit_printf(connsetup, "Interface %s Unhandled error in accept callback: %s\n", self->name.c_str(), e.what());
|
||||
log_exc_printf(connsetup, "Interface %s Unhandled error in accept callback: %s\n", self->name.c_str(), e.what());
|
||||
evutil_closesocket(sock);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user