diff options
author | Karsten Loesing <karsten.loesing@gmx.net> | 2010-08-27 08:13:54 +0200 |
---|---|---|
committer | Karsten Loesing <karsten.loesing@gmx.net> | 2010-10-04 08:15:18 +0200 |
commit | 8c5ba9388bd372316cc18f23dcb6d41b4c1e9546 (patch) | |
tree | 61b6ad3662920c53b73aca49ba9d881e5fc2f0c8 /src/common/log.c | |
parent | 80b515b85fdfbcd645cb1920e398b3f2f6e85a31 (diff) | |
download | tor-8c5ba9388bd372316cc18f23dcb6d41b4c1e9546.tar.gz tor-8c5ba9388bd372316cc18f23dcb6d41b4c1e9546.zip |
Make logging resolution configurable.
Implements enhancement 1668.
Diffstat (limited to 'src/common/log.c')
-rw-r--r-- | src/common/log.c | 25 |
1 files changed, 22 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 |