From 2219ad50a02c39625cce3330c6e4e469fb3bea70 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Fri, 3 Apr 2020 10:34:43 -0700 Subject: [PATCH] _PVXS_ABORT_ON_CRIT --- src/log.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/log.cpp b/src/log.cpp index cf6df44..9defd58 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -8,6 +8,8 @@ #include #include +#include + // must include before epicsStdio.h to avoid clash with printf macro #include #include @@ -37,6 +39,21 @@ DEFINE_LOGGER(logerr, "pvxs.ev"); namespace detail { +static +void maybeAbort() +{ + static std::atomic abort_check{}; + auto check = abort_check.load(); + if(abort_check==0) { + check = getenv("_PVXS_ABORT_ON_CRIT") ? 1 : -1; + abort_check = check; + } + if(check==1) { + errlogFlush(); + abort(); + } +} + const char* log_prefix(const char* name, Level lvl) { static thread_local char prefix[64]; @@ -64,6 +81,9 @@ const char* log_prefix(const char* name, Level lvl) epicsSnprintf(prefix+N, sizeof(prefix)-N, " %s %s", lname, name); + if(lvl==Level::Crit) + maybeAbort(); + return prefix; }