Main Page | Modules | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

event_log.c

Go to the documentation of this file.
00001 /*
00002 ** Copyright (C) 2005 by Kevin L. Mitchell <klmitch@mit.edu>
00003 **
00004 ** This program is free software; you can redistribute it and/or modify
00005 ** it under the terms of the GNU General Public License as published by
00006 ** the Free Software Foundation; either version 2 of the License, or
00007 ** (at your option) any later version.
00008 **
00009 ** This program is distributed in the hope that it will be useful,
00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 ** GNU General Public License for more details.
00013 **
00014 ** You should have received a copy of the GNU General Public License
00015 ** along with this program; if not, write to the Free Software
00016 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 **
00018 ** @(#)$Id: event_log.c,v 1.7 2005/12/18 00:15:11 klmitch Exp $
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; /* zero assertion flags */
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; /* set up default logging routine */
00065 
00066 /* set the logging function pointer to the user-specified function */
00067 ev_err_t
00068 event_log_set(ev_log_t logger)
00069 {
00070   ev_init(); /* initialize the library */
00071 
00072   _ev_debuglog = logger;
00073   _ev_asflags |= EVAS_LOG; /* setting logger implies logging */
00074 
00075   ev_return(0);
00076 }
00077 
00078 /* reset the logging function pointer to its default */
00079 ev_err_t
00080 event_log_reset(void)
00081 {
00082   ev_init(); /* initialize the library */
00083 
00084   _ev_debuglog = deflog;
00085   _ev_asflags &= ~(EVAS_LOG | EVAS_TRACE); /* reset logging flags as well */
00086 
00087   ev_return(0);
00088 }
00089 
00090 /* turn debug logging on or off */
00091 ev_err_t
00092 event_log_debug(int onoff)
00093 {
00094   ev_init(); /* initialize the library */
00095 
00096   if (onoff) /* turning it on? */
00097     _ev_asflags |= EVAS_LOG;
00098   else /* OK, turning it off */
00099     _ev_asflags &= ~EVAS_LOG;
00100 
00101   ev_return(0);
00102 }
00103 
00104 /* turn tracing on or off */
00105 ev_err_t
00106 event_log_trace(int onoff)
00107 {
00108   ev_init(); /* initialize the library */
00109 
00110   if (onoff) /* turning it on? */
00111     _ev_asflags |= EVAS_TRACE;
00112   else /* OK, turning it off */
00113     _ev_asflags &= ~EVAS_TRACE;
00114 
00115   ev_return(0);
00116 }
00117 
00118 /* manipulate abort flag */
00119 ev_err_t
00120 event_log_abort(int onoff)
00121 {
00122   ev_init(); /* initialize the library */
00123 
00124   if (onoff) /* turning it on? */
00125     _ev_asflags |= EVAS_ABORT;
00126   else /* OK, turning it off */
00127     _ev_asflags &= ~EVAS_ABORT;
00128 
00129   ev_return(0);
00130 }
00131 
00132 /* log a debug message */
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; /* no sense continuing... */
00142 
00143   va_start(vp, fmt);
00144   vsnprintf(buf, sizeof(buf), fmt, vp); /* format log message */
00145   va_end(vp);
00146 
00147   /* call user logging function */
00148   (_ev_debuglog)(file, line, func, buf);
00149 }

Generated on Wed Dec 28 23:36:56 2005 for event by  doxygen 1.4.4