diff options
-rw-r--r-- | src/common/log.c | 26 | ||||
-rw-r--r-- | src/common/log.h | 4 | ||||
-rw-r--r-- | src/or/test.c | 3 | ||||
-rw-r--r-- | src/tools/tor-gencert.c | 11 | ||||
-rw-r--r-- | src/tools/tor-resolve.c | 11 |
5 files changed, 29 insertions, 26 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(); diff --git a/src/common/log.h b/src/common/log.h index 994ec7d0ff..c752d40b85 100644 --- a/src/common/log.h +++ b/src/common/log.h @@ -104,9 +104,11 @@ typedef struct log_severity_list_t { log_domain_mask_t masks[LOG_DEBUG-LOG_ERR+1]; } log_severity_list_t; +#ifdef LOG_PRIVATE /** Given a severity, yields an index into log_severity_list_t.masks to use * for that severity. */ #define SEVERITY_MASK_IDX(sev) ((sev) - LOG_ERR) +#endif /** Callback type used for add_callback_log. */ typedef void (*log_callback)(int severity, uint32_t domain, const char *msg); @@ -116,6 +118,8 @@ int parse_log_level(const char *level); const char *log_level_to_string(int level); int parse_log_severity_config(const char **cfg, log_severity_list_t *severity_out); +void set_log_severity_config(int minSeverity, int maxSeverity, + log_severity_list_t *severity_out); void add_stream_log(log_severity_list_t *severity, const char *name, FILE *stream); int add_file_log(log_severity_list_t *severity, const char *filename); diff --git a/src/or/test.c b/src/or/test.c index 371d32309d..32e22cb754 100644 --- a/src/or/test.c +++ b/src/or/test.c @@ -3636,8 +3636,7 @@ main(int c, char**v) { log_severity_list_t *s = tor_malloc_zero(sizeof(log_severity_list_t)); - for (i = loglevel; i >= LOG_ERR; --i) - s->masks[SEVERITY_MASK_IDX(i)] = ~0u; + set_log_severity_config(loglevel, LOG_ERR, s); add_stream_log(s, "", stdout); } diff --git a/src/tools/tor-gencert.c b/src/tools/tor-gencert.c index 1f4b2c5e59..da037d3208 100644 --- a/src/tools/tor-gencert.c +++ b/src/tools/tor-gencert.c @@ -190,13 +190,10 @@ parse_commandline(int argc, char **argv) } s = tor_malloc_zero(sizeof(log_severity_list_t)); - s->masks[SEVERITY_MASK_IDX(LOG_ERR)] = ~0u; - s->masks[SEVERITY_MASK_IDX(LOG_WARN)] = ~0u; - if (verbose) { - s->masks[SEVERITY_MASK_IDX(LOG_NOTICE)] = ~0u; - s->masks[SEVERITY_MASK_IDX(LOG_INFO)] = ~0u; - s->masks[SEVERITY_MASK_IDX(LOG_DEBUG)] = ~0u; - } + if (verbose) + set_log_severity_config(LOG_DEBUG, LOG_ERR, s); + else + set_log_severity_config(LOG_WARN, LOG_ERR, s); add_stream_log(s, "<stderr>", stderr); if (!identity_key_file) { diff --git a/src/tools/tor-resolve.c b/src/tools/tor-resolve.c index ab43719e62..fb4f13ff45 100644 --- a/src/tools/tor-resolve.c +++ b/src/tools/tor-resolve.c @@ -318,13 +318,10 @@ main(int argc, char **argv) usage(); } - s->masks[SEVERITY_MASK_IDX(LOG_ERR)] = ~0u; - s->masks[SEVERITY_MASK_IDX(LOG_WARN)] = ~0u; - if (isVerbose) { - s->masks[SEVERITY_MASK_IDX(LOG_NOTICE)] = ~0u; - s->masks[SEVERITY_MASK_IDX(LOG_INFO)] = ~0u; - s->masks[SEVERITY_MASK_IDX(LOG_DEBUG)] = ~0u; - } + if (isVerbose) + set_log_severity_config(LOG_DEBUG, LOG_ERR, s); + else + set_log_severity_config(LOG_WARN, LOG_ERR, s); add_stream_log(s, "<stderr>", stderr); if (n_args == 1) { |