diff options
author | Nick Mathewson <nickm@torproject.org> | 2010-11-08 12:40:33 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2010-11-08 12:40:33 -0500 |
commit | 1fb342dfab42f47a2e87d38c536bb9a52f1a0fcd (patch) | |
tree | 51e8c4134a29c98facf8ebf7b8ce4b7903bd0d50 /src/common | |
parent | d96c9cd00e35ed1ab4e280cb70fa5dae93002a71 (diff) | |
parent | 152c9cba65b85fb034f10b3485b5011ecff06f36 (diff) | |
download | tor-1fb342dfab42f47a2e87d38c536bb9a52f1a0fcd.tar.gz tor-1fb342dfab42f47a2e87d38c536bb9a52f1a0fcd.zip |
Merge branch 'loggranularity'
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/log.c | 25 | ||||
-rw-r--r-- | src/common/torlog.h | 1 |
2 files changed, 23 insertions, 3 deletions
diff --git a/src/common/log.c b/src/common/log.c index b639e7a781..e507275830 100644 --- a/src/common/log.c +++ b/src/common/log.c @@ -131,6 +131,17 @@ log_set_application_name(const char *name) appname = name ? tor_strdup(name) : NULL; } +/** Log time granularity in milliseconds. */ +static int log_time_granularity = 1; + +/** Define log time granularity for all logs to be <b>granularity_msec</b> + * milliseconds. */ +void +set_log_time_granularity(int granularity_msec) +{ + log_time_granularity = granularity_msec; +} + /** Helper: Write the standard prefix for log lines to a * <b>buf_len</b> character buffer in <b>buf</b>. */ @@ -141,14 +152,22 @@ _log_prefix(char *buf, size_t buf_len, int severity) struct timeval now; struct tm tm; size_t n; - int r; + int r, ms; tor_gettimeofday(&now); t = (time_t)now.tv_sec; + ms = (int)now.tv_usec / 1000; + if (log_time_granularity >= 1000) { + t -= t % (log_time_granularity / 1000); + ms = 0; + } else { + ms -= ((int)now.tv_usec / 1000) % log_time_granularity; + } n = strftime(buf, buf_len, "%b %d %H:%M:%S", tor_localtime_r(&t, &tm)); - r = tor_snprintf(buf+n, buf_len-n, ".%.3i [%s] ", - (int)now.tv_usec / 1000, sev_to_string(severity)); + r = tor_snprintf(buf+n, buf_len-n, ".%.3i [%s] ", ms, + sev_to_string(severity)); + if (r<0) return buf_len-1; else diff --git a/src/common/torlog.h b/src/common/torlog.h index 21219569e3..d119993e87 100644 --- a/src/common/torlog.h +++ b/src/common/torlog.h @@ -138,6 +138,7 @@ void mark_logs_temp(void); void change_callback_log_severity(int loglevelMin, int loglevelMax, log_callback cb); void log_set_application_name(const char *name); +void set_log_time_granularity(int granularity_msec); /* Outputs a message to stdout */ void tor_log(int severity, log_domain_mask_t domain, const char *format, ...) |