[or-cvs] Add a callback log handler type
Nick Mathewson
nickm at seul.org
Wed Nov 3 18:27:21 UTC 2004
Update of /home/or/cvsroot/src/common
In directory moria.mit.edu:/tmp/cvs-serv12619/src/common
Modified Files:
log.c log.h
Log Message:
Add a callback log handler type
Index: log.c
===================================================================
RCS file: /home/or/cvsroot/src/common/log.c,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -d -r1.58 -r1.59
--- log.c 27 Oct 2004 21:14:10 -0000 1.58
+++ log.c 3 Nov 2004 18:27:19 -0000 1.59
@@ -29,6 +29,7 @@
int max_loglevel; /**< Highest severity level to send to this stream. */
int is_temporary; /**< Boolean: close after initializing logging subsystem.*/
int is_syslog; /**< Boolean: send messages to syslog. */
+ log_callback callback; /**< If not num, send messages to this function. */
} logfile_t;
/** Helper: map a log severity to descriptive string. */
@@ -156,7 +157,7 @@
lf = lf->next;
continue;
}
- if (! (lf->file || lf->is_syslog)) {
+ if (! (lf->file || lf->is_syslog || lf->callback)) {
lf = lf->next;
continue;
}
@@ -172,6 +173,10 @@
#endif
lf = lf->next;
continue;
+ } else if (lf->callback) {
+ lf->callback(severity, end_of_prefix);
+ lf = lf->next;
+ continue;
}
if(fputs(buf, lf->file) == EOF ||
fflush(lf->file) == EOF) { /* error */
@@ -300,6 +305,19 @@
logfiles->is_temporary = 1;
}
+int add_callback_log(int loglevelMin, int loglevelMax, log_callback cb)
+{
+ logfile_t *lf;
+ lf = tor_malloc_zero(sizeof(logfile_t));
+ lf->loglevel = loglevelMin;
+ lf->max_loglevel = loglevelMax;
+ lf->filename = tor_strdup("callback>");
+ lf->callback = cb;
+ lf->next = logfiles;
+ logfiles = lf;
+ return 0;
+}
+
/** Close any log handlers added by add_temp_log or marked by mark_logs_temp */
void close_temp_logs(void)
{
Index: log.h
===================================================================
RCS file: /home/or/cvsroot/src/common/log.h,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- log.h 1 Nov 2004 20:41:47 -0000 1.30
+++ log.h 3 Nov 2004 18:27:19 -0000 1.31
@@ -53,12 +53,15 @@
#define LOG_ERR 3
#endif
+typedef void (*log_callback)(int severity, const char *msg);
+
int parse_log_level(const char *level);
void add_stream_log(int severityMin, int severityMax, const char *name, FILE *stream);
int add_file_log(int severityMin, int severityMax, const char *filename);
#ifdef HAVE_SYSLOG_H
int add_syslog_log(int loglevelMin, int loglevelMax);
#endif
+int add_callback_log(int loglevelMin, int loglevelMax, log_callback cb);
int get_min_log_level(void);
void close_logs(void);
void reset_logs(void);
More information about the tor-commits
mailing list