automatic evhelper_ev2err
This commit is contained in:
@@ -181,31 +181,6 @@ void evbase::assertInLoop()
|
||||
assert(pvt->worker.isCurrentThread());
|
||||
}
|
||||
|
||||
|
||||
static
|
||||
void evlog_handler(int severity, const char *msg)
|
||||
{
|
||||
const char *sevr = "<\?\?\?>";
|
||||
int lvl = PLVL_CRIT;
|
||||
switch(severity) {
|
||||
#define CASE(EVLVL, PLVL) case EVENT_LOG_##EVLVL : lvl = PLVL_##PLVL; sevr = #PLVL; break
|
||||
CASE(DEBUG, DEBUG);
|
||||
CASE(MSG, INFO);
|
||||
CASE(WARN, WARN);
|
||||
CASE(ERR, ERR);
|
||||
#undef CASE
|
||||
}
|
||||
log_printf(logerr, lvl, "libevent %s: %s\n", sevr, msg);
|
||||
}
|
||||
|
||||
void evhelper_ev2err()
|
||||
{
|
||||
event_set_log_callback(&evlog_handler);
|
||||
|
||||
// Hook in to use epicsAssert() ?
|
||||
// event_set_fatal_callback()
|
||||
}
|
||||
|
||||
evevent::evevent(struct event_base *base, evutil_socket_t sock, short mask, event_callback_fn fn, void *arg)
|
||||
:ev(event_new(base, sock, mask, fn, arg))
|
||||
{
|
||||
|
||||
+2
-4
@@ -23,7 +23,8 @@
|
||||
namespace pvxsimpl {
|
||||
using namespace pvxs;
|
||||
|
||||
// in-line string builder (eg. for exception messages)
|
||||
//! in-line string builder (eg. for exception messages)
|
||||
//! eg. @code throw std::runtime_error(SB()<<"Some message"<<42); @endcode
|
||||
struct SB {
|
||||
std::ostringstream strm;
|
||||
SB() {}
|
||||
@@ -35,9 +36,6 @@ struct SB {
|
||||
//! prepare libevent for use by multiple threads
|
||||
PVXS_API void evhelper_setup_thread();
|
||||
|
||||
//! Setup forwarding of libevent log messages to errlog
|
||||
PVXS_API void evhelper_ev2err();
|
||||
|
||||
//! Block the calling thread until any callback in-progress in the
|
||||
//! specified loop has completed.
|
||||
PVXS_API void evhelper_sync(event_base *base);
|
||||
|
||||
+25
@@ -17,13 +17,33 @@
|
||||
#include <epicsMutex.h>
|
||||
#include <epicsGuard.h>
|
||||
|
||||
#include "evhelper.h"
|
||||
|
||||
typedef epicsGuard<epicsMutex> Guard;
|
||||
|
||||
namespace {
|
||||
using namespace pvxs;
|
||||
|
||||
DEFINE_LOGGER(logerr, "evlog");
|
||||
|
||||
epicsThreadOnceId logger_once = EPICS_THREAD_ONCE_INIT;
|
||||
|
||||
void evlog_handler(int severity, const char *msg)
|
||||
{
|
||||
const char *sevr = "<\?\?\?>";
|
||||
int lvl = PLVL_CRIT;
|
||||
switch(severity) {
|
||||
#define CASE(EVLVL, PLVL) case EVENT_LOG_##EVLVL : lvl = PLVL_##PLVL; sevr = #PLVL; break
|
||||
CASE(DEBUG, DEBUG);
|
||||
CASE(MSG, INFO);
|
||||
CASE(WARN, WARN);
|
||||
CASE(ERR, ERR);
|
||||
#undef CASE
|
||||
}
|
||||
log_printf(logerr, lvl, "libevent %s: %s\n", sevr, msg);
|
||||
}
|
||||
|
||||
|
||||
int name2lvl(const std::string& name)
|
||||
{
|
||||
#define CASE(LVL) if(name==#LVL) return PLVL_##LVL
|
||||
@@ -41,6 +61,11 @@ struct logger_gbl_t {
|
||||
std::map<std::string, int> config;
|
||||
std::multimap<std::string, logger*> loggers;
|
||||
|
||||
logger_gbl_t()
|
||||
{
|
||||
event_set_log_callback(&evlog_handler);
|
||||
}
|
||||
|
||||
int init(logger *logger)
|
||||
{
|
||||
std::string name(logger->name);
|
||||
|
||||
Reference in New Issue
Block a user