00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00027 #include "event_int.h"
00028
00029 #include <stdarg.h>
00030 #include <stdio.h>
00031
00032 RCSTAG("@(#)$Id: event_log.c,v 1.7 2005/12/18 00:15:11 klmitch Exp $");
00033
00039 #define DEBUG_BUF 1024
00040
00041 ev_flags_t _ev_asflags = 0;
00042
00057 static void
00058 deflog(const char *file, int line, const char *func, const char *msg)
00059 {
00060 fprintf(stderr, "%s:%d%s%s%s: %s\n", file, line,
00061 func ? " (" : "", func ? func : "", func ? ")" : "", msg);
00062 }
00063
00064 ev_log_t _ev_debuglog = deflog;
00065
00066
00067 ev_err_t
00068 event_log_set(ev_log_t logger)
00069 {
00070 ev_init();
00071
00072 _ev_debuglog = logger;
00073 _ev_asflags |= EVAS_LOG;
00074
00075 ev_return(0);
00076 }
00077
00078
00079 ev_err_t
00080 event_log_reset(void)
00081 {
00082 ev_init();
00083
00084 _ev_debuglog = deflog;
00085 _ev_asflags &= ~(EVAS_LOG | EVAS_TRACE);
00086
00087 ev_return(0);
00088 }
00089
00090
00091 ev_err_t
00092 event_log_debug(int onoff)
00093 {
00094 ev_init();
00095
00096 if (onoff)
00097 _ev_asflags |= EVAS_LOG;
00098 else
00099 _ev_asflags &= ~EVAS_LOG;
00100
00101 ev_return(0);
00102 }
00103
00104
00105 ev_err_t
00106 event_log_trace(int onoff)
00107 {
00108 ev_init();
00109
00110 if (onoff)
00111 _ev_asflags |= EVAS_TRACE;
00112 else
00113 _ev_asflags &= ~EVAS_TRACE;
00114
00115 ev_return(0);
00116 }
00117
00118
00119 ev_err_t
00120 event_log_abort(int onoff)
00121 {
00122 ev_init();
00123
00124 if (onoff)
00125 _ev_asflags |= EVAS_ABORT;
00126 else
00127 _ev_asflags &= ~EVAS_ABORT;
00128
00129 ev_return(0);
00130 }
00131
00132
00133 void
00134 _ev_debug(ev_flags_t flags, const char *file, int line, const char *func,
00135 const char *fmt, ...)
00136 {
00137 va_list vp;
00138 char buf[DEBUG_BUF];
00139
00140 if (!(_ev_asflags & flags) || !_ev_debuglog)
00141 return;
00142
00143 va_start(vp, fmt);
00144 vsnprintf(buf, sizeof(buf), fmt, vp);
00145 va_end(vp);
00146
00147
00148 (_ev_debuglog)(file, line, func, buf);
00149 }