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; }