aboutsummaryrefslogtreecommitdiff
path: root/src/common/log.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2004-11-03 18:27:19 +0000
committerNick Mathewson <nickm@torproject.org>2004-11-03 18:27:19 +0000
commit11979dc1f5fae74df8fba8c339f0ac5ee4c52796 (patch)
tree1475a888a00ef3bb492bf54bd4c4f2a05235d841 /src/common/log.c
parent4fdaa5de51f6dbe6c56545553c617fc40eabf138 (diff)
downloadtor-11979dc1f5fae74df8fba8c339f0ac5ee4c52796.tar
tor-11979dc1f5fae74df8fba8c339f0ac5ee4c52796.tar.gz
Add a callback log handler type
svn:r2658
Diffstat (limited to 'src/common/log.c')
-rw-r--r--src/common/log.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/common/log.c b/src/common/log.c
index 8fbb343a9..f8f80b909 100644
--- a/src/common/log.c
+++ b/src/common/log.c
@@ -29,6 +29,7 @@ typedef struct logfile_t {
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 @@ logv(int severity, const char *funcname, const char *format, va_list ap)
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 @@ logv(int severity, const char *funcname, const char *format, va_list ap)
#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 @@ void add_temp_log(void)
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)
{