diff options
author | Nick Mathewson <nickm@torproject.org> | 2004-05-19 20:07:08 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2004-05-19 20:07:08 +0000 |
commit | 9d2cd7fc6e01ee5aafeaf222b5020c464a01a03d (patch) | |
tree | 6aed917dcc979673b9870fd29ed41b07e1b36f44 /src/common | |
parent | 1a829b0df4faf09546d9e4e9bbcc657405aee94a (diff) | |
download | tor-9d2cd7fc6e01ee5aafeaf222b5020c464a01a03d.tar tor-9d2cd7fc6e01ee5aafeaf222b5020c464a01a03d.tar.gz |
Allow multiple logfiles at different severity ranges
svn:r1899
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/log.c | 38 | ||||
-rw-r--r-- | src/common/log.h | 6 |
2 files changed, 37 insertions, 7 deletions
diff --git a/src/common/log.c b/src/common/log.c index 136ea66fc..0581bd792 100644 --- a/src/common/log.c +++ b/src/common/log.c @@ -11,6 +11,7 @@ #include <stdarg.h> #include <assert.h> #include <stdlib.h> +#include <string.h> #include "orconfig.h" #include "./util.h" #include "./log.h" @@ -162,14 +163,14 @@ void reset_logs() /** Add a log handler to send all messages of severity <b>loglevel</b> * or higher to <b>stream</b>. */ -void add_stream_log(int loglevel, const char *name, FILE *stream) +void add_stream_log(int loglevelMin, int loglevelMax, const char *name, FILE *stream) { logfile_t *lf; lf = tor_malloc(sizeof(logfile_t)); lf->filename = name; lf->needs_close = 0; - lf->loglevel = loglevel; - lf->max_loglevel = LOG_ERR; + lf->loglevel = loglevelMin; + lf->max_loglevel = loglevelMax; lf->file = stream; lf->next = logfiles; logfiles = lf; @@ -180,16 +181,43 @@ void add_stream_log(int loglevel, const char *name, FILE *stream) * the logfile fails, -1 is returned and errno is set appropriately * (by fopen). */ -int add_file_log(int loglevel, const char *filename) +int add_file_log(int loglevelMin, int loglevelMax, const char *filename) { FILE *f; f = fopen(filename, "a"); if (!f) return -1; - add_stream_log(loglevel, filename, f); + add_stream_log(loglevelMin, loglevelMax, filename, f); logfiles->needs_close = 1; return 0; } +/** If <b>level</b> is a valid log severity, return the corresponding + * numeric value. Otherwise, return -1. */ +int parse_log_level(const char *level) { + if (!strcasecmp(level, "err")) + return LOG_ERR; + else if (!strcasecmp(level, "notice")) + return LOG_NOTICE; + else if (!strcasecmp(level, "info")) + return LOG_INFO; + else if (!strcasecmp(level, "debug")) + return LOG_DEBUG; + else + return -1; +} + +int get_min_log_level(void) +{ + logfile_t *lf; + int min = LOG_ERR; + for (lf = logfiles; lf; lf = lf->next) { + if (lf->loglevel < min) + min = lf->loglevel; + } + return min; +} + + /* Local Variables: mode:c diff --git a/src/common/log.h b/src/common/log.h index fa830a9b4..786e7fcc1 100644 --- a/src/common/log.h +++ b/src/common/log.h @@ -46,8 +46,10 @@ #define CHECK_PRINTF(formatIdx, firstArg) #endif -void add_stream_log(int loglevel, const char *name, FILE *stream); -int add_file_log(int severity, const char *filename); +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); +int get_min_log_level(void); void close_logs(); void reset_logs(); |