diff options
author | Nick Mathewson <nickm@torproject.org> | 2008-03-13 22:18:38 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2008-03-13 22:18:38 +0000 |
commit | 46155aca171796396449a55aa24888a9a7372ed6 (patch) | |
tree | 2499f5c7064bd7ddb03695a24e03c6b28304f177 /src/common/log.c | |
parent | d928e5685f1170d907a47ee95e35c9b92c28adef (diff) | |
download | tor-46155aca171796396449a55aa24888a9a7372ed6.tar.gz tor-46155aca171796396449a55aa24888a9a7372ed6.zip |
r18804@catbus: nickm | 2008-03-13 18:18:31 -0400
Refactor log domain mask code so that nobody outside of log.c has to use SEVERITY_MASK_IDX. It is error-prone.
svn:r14016
Diffstat (limited to 'src/common/log.c')
-rw-r--r-- | src/common/log.c | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/src/common/log.c b/src/common/log.c index a823faa0b8..8f55694ace 100644 --- a/src/common/log.c +++ b/src/common/log.c @@ -24,6 +24,7 @@ const char log_c_id[] = "$Id$"; #include <time.h> #endif #include "util.h" +#define LOG_PRIVATE #include "log.h" #include "container.h" @@ -474,16 +475,21 @@ close_log(logfile_t *victim) } } -/** DOCDOC XXXX021 remove me. */ -static log_severity_list_t * -new_severity_list(int loglevelMin, int loglevelMax) +/** Adjust a log severity configuration in <b>severity_out</b> to contain + * every domain between <b>loglevelMin</b> and <b>loglevelMax</b>, inclusive. + */ +void +set_log_severity_config(int loglevelMin, int loglevelMax, + log_severity_list_t *severity_out) { - log_severity_list_t *out = tor_malloc_zero(sizeof(log_severity_list_t)); int i; + tor_assert(loglevelMin >= loglevelMax); + tor_assert(loglevelMin >= LOG_ERR && loglevelMin <= LOG_DEBUG); + tor_assert(loglevelMax >= LOG_ERR && loglevelMax <= LOG_DEBUG); + memset(severity_out, 0, sizeof(log_severity_list_t)); for (i = loglevelMin; i >= loglevelMax; --i) { - out->masks[SEVERITY_MASK_IDX(i)] = ~0u; + severity_out->masks[SEVERITY_MASK_IDX(i)] = ~0u; } - return out; } /** Add a log handler named <b>name</b> to send all messages in <b>severity</b> @@ -529,9 +535,10 @@ init_logging(void) void add_temp_log(void) { + log_severity_list_t *s = tor_malloc_zero(sizeof(log_severity_list_t)); + set_log_severity_config(LOG_NOTICE, LOG_ERR, s); LOCK_LOGS(); - add_stream_log_impl(new_severity_list(LOG_NOTICE, LOG_ERR), - "<temp>", stdout); + add_stream_log_impl(s, "<temp>", stdout); logfiles->is_temporary = 1; UNLOCK_LOGS(); } @@ -567,8 +574,7 @@ change_callback_log_severity(int loglevelMin, int loglevelMax, LOCK_LOGS(); for (lf = logfiles; lf; lf = lf->next) { if (lf->callback == cb) { - tor_free(lf->severities); - lf->severities = new_severity_list(loglevelMin, loglevelMax); + set_log_severity_config(loglevelMin, loglevelMax, lf->severities); } } _log_global_min_severity = get_min_log_level(); |