[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] Use recent libevent features when possible



Update of /home/or/cvsroot/tor/src/common
In directory moria.mit.edu:/tmp/cvs-serv10383/src/common

Modified Files:
	log.c log.h 
Log Message:
Use recent libevent features when possible

Index: log.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/log.c,v
retrieving revision 1.87
retrieving revision 1.88
diff -u -d -r1.87 -r1.88
--- log.c	17 Mar 2005 12:38:35 -0000	1.87
+++ log.c	1 Apr 2005 02:37:39 -0000	1.88
@@ -17,6 +17,12 @@
 #include "./util.h"
 #include "./log.h"
 
+#ifdef HAVE_EVENT_H
+#include <event.h>
+#else
+#error "Tor requires libevent to build."
+#endif
+
 #define TRUNCATED_STR "[...truncated]"
 #define TRUNCATED_STR_LEN 14
 
@@ -475,3 +481,31 @@
   }
 }
 
+#ifdef HAVE_EVENT_SET_LOG_CALLBACK
+void libevent_logging_callback(int severity, const char *msg)
+{
+  switch (severity) {
+    case _EVENT_LOG_DEBUG:
+      log(LOG_DEBUG, "Message from libevent: %s", msg);
+      break;
+    case _EVENT_LOG_MSG:
+      log(LOG_INFO, "Message from libevent: %s", msg);
+      break;
+    case _EVENT_LOG_WARN:
+      log(LOG_WARN, "Warning from libevent: %s", msg);
+      break;
+    case _EVENT_LOG_ERR:
+      log(LOG_ERR, "Error from libevent: %s", msg);
+      break;
+    default:
+      log(LOG_WARN, "Message [%d] from libevent: %s", severity, msg);
+      break;
+  }
+}
+void configure_libevent_logging(void)
+{
+  event_set_log_callback(libevent_logging_callback);
+}
+#else
+void configure_libevent_logging(void) {}
+#endif

Index: log.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/log.h,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -d -r1.40 -r1.41
--- log.h	30 Nov 2004 06:17:34 -0000	1.40
+++ log.h	1 Apr 2005 02:37:39 -0000	1.41
@@ -66,6 +66,7 @@
 void add_temp_log(void);
 void close_temp_logs(void);
 void mark_logs_temp(void);
+void configure_libevent_logging(void);
 
 /* Outputs a message to stdout */
 void _log(int severity, const char *format, ...) CHECK_PRINTF(2,3);