diff options
author | Nick Mathewson <nickm@torproject.org> | 2004-05-20 19:47:28 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2004-05-20 19:47:28 +0000 |
commit | ccb825128e60e924c9f2c106d94c4519d4393d8e (patch) | |
tree | 08735f6d83ef316b1ed81bdcf1d1650295a5f213 /src/common/log.c | |
parent | 1c21a02b90a7cef6d56589194f22b2a7f4f35f95 (diff) | |
download | tor-ccb825128e60e924c9f2c106d94c4519d4393d8e.tar.gz tor-ccb825128e60e924c9f2c106d94c4519d4393d8e.zip |
Tinker with log behavior: never send error messages about logs into the bitbucket
svn:r1912
Diffstat (limited to 'src/common/log.c')
-rw-r--r-- | src/common/log.c | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/src/common/log.c b/src/common/log.c index 0581bd792a..1b77cc49ae 100644 --- a/src/common/log.c +++ b/src/common/log.c @@ -25,11 +25,12 @@ /** Information for a single logfile; only used in log.c */ typedef struct logfile_t { struct logfile_t *next; /**< Next logfile_t in the linked list. */ - const char *filename; /**< Filename to open. */ + char *filename; /**< Filename to open. */ FILE *file; /**< Stream to receive log messages. */ int needs_close; /**< Boolean: true if the stream gets closed on shutdown. */ int loglevel; /**< Lowest severity level to send to this stream. */ int max_loglevel; /**< Highest severity level to send to this stream. */ + int is_temporary; /**< Boolean: close after initializing logging subsystem.*/ } logfile_t; /** Helper: map a log severity to descriptive string. */ @@ -145,7 +146,8 @@ void close_logs() logfiles = logfiles->next; if (victim->needs_close) fclose(victim->file); - free(victim); + tor_free(victim->filename); + tor_free(victim); } } @@ -167,15 +169,42 @@ void add_stream_log(int loglevelMin, int loglevelMax, const char *name, FILE *st { logfile_t *lf; lf = tor_malloc(sizeof(logfile_t)); - lf->filename = name; + lf->filename = tor_strdup(name); lf->needs_close = 0; lf->loglevel = loglevelMin; lf->max_loglevel = loglevelMax; lf->file = stream; lf->next = logfiles; + lf->is_temporary = 0; logfiles = lf; } +/** Add a log handler to receive messages during startup (before the real + * logs are initialized). + */ +void add_temp_log(void) +{ + add_stream_log(LOG_INFO, LOG_ERR, "<temp>", stdout); + logfiles->is_temporary = 1; +} + +void close_temp_logs(void) +{ + logfile_t *lf, **p; + for (p = &logfiles; *p; ) { + if ((*p)->is_temporary) { + lf = *p; + *p = (*p)->next; + if (lf->needs_close) + fclose(lf->file); + tor_free(lf->filename); + tor_free(lf); + } else { + p = &((*p)->next); + } + } +} + /** * Add a log handler to send messages to <b>filename</b>. If opening * the logfile fails, -1 is returned and errno is set appropriately |