#defineEVENT_LOG_DEBUG0#defineEVENT_LOG_MSG1#defineEVENT_LOG_WARN2#defineEVENT_LOG_ERR3/* Deprecated; see note at the end of this section */#define_EVENT_LOG_DEBUG EVENT_LOG_DEBUG#define_EVENT_LOG_MSG EVENT_LOG_MSG#define_EVENT_LOG_WARN EVENT_LOG_WARN#define_EVENT_LOG_ERR EVENT_LOG_ERRtypedefvoid (*event_log_cb)(int severity,constchar*msg);voidevent_set_log_callback(event_log_cb cb);
#include<event2/event.h>#include<stdio.h>staticvoiddiscard_cb(int severity,constchar*msg){ /* This callback does nothing. */}static FILE *logfile =NULL;staticvoidwrite_to_file_cb(int severity,constchar*msg){constchar*s;if (!logfile)return;switch (severity) {case _EVENT_LOG_DEBUG: s ="debug"; break;case _EVENT_LOG_MSG: s ="msg"; break;case _EVENT_LOG_WARN: s ="warn"; break;case _EVENT_LOG_ERR: s ="error"; break;default: s ="?"; break; /* never reached */ }fprintf(logfile,"[%s] %s\n", s, msg);}/* Turn off all logging from Libevent. */voidsuppress_logging(void){event_set_log_callback(discard_cb);}/* Redirect all Libevent log messages to the C stdio file 'f'. */voidset_logfile(FILE*f){ logfile = f;event_set_log_callback(write_to_file_cb);}