diff options
-rw-r--r-- | doc/tor.1.txt | 5 | ||||
-rw-r--r-- | src/or/config.c | 30 |
2 files changed, 27 insertions, 8 deletions
diff --git a/doc/tor.1.txt b/doc/tor.1.txt index 5d6a959be..f6662771d 100644 --- a/doc/tor.1.txt +++ b/doc/tor.1.txt @@ -346,7 +346,10 @@ Other options can be specified either on the command-line (--option **LogTimeGranularity** __NUM__:: Set the resolution of timestamps in Tor's logs to NUM milliseconds. NUM must be positive and either a divisor or a multiple of 1 second. - (Default: 1 second) + Note that this option only controls the granularity written by Tor to + a file or console log. Tor does not (for example) "batch up" log + messages to affect times logged by a controller, times attached to + syslog messages, or the mtime fields on log files. (Default: 1 second) **SafeLogging** **0**|**1**|**relay**:: Tor can scrub potentially sensitive strings from log messages (e.g. diff --git a/src/or/config.c b/src/or/config.c index 111247894..0251ef49d 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -4342,15 +4342,31 @@ options_init_logs(or_options_t *options, int validate_only) options->RunAsDaemon; #endif - if (options->LogTimeGranularity > 0 && - (1000 % options->LogTimeGranularity == 0 || - options->LogTimeGranularity % 1000 == 0)) { - set_log_time_granularity(options->LogTimeGranularity); - } else { - log_warn(LD_CONFIG, "Log time granularity '%d' has to be positive " - "and either a divisor or a multiple of 1 second.", + if (options->LogTimeGranularity <= 0) { + log_warn(LD_CONFIG, "Log time granularity '%d' has to be positive.", options->LogTimeGranularity); return -1; + } else if (1000 % options->LogTimeGranularity != 0 && + options->LogTimeGranularity % 1000 != 0) { + int granularity = options->LogTimeGranularity; + if (granularity < 40) { + do granularity++; + while (1000 % granularity != 0); + } else if (granularity < 1000) { + granularity = 1000 / granularity; + while (1000 % granularity != 0) + granularity--; + granularity = 1000 / granularity; + } else { + granularity = 1000 * ((granularity / 1000) + 1); + } + log_warn(LD_CONFIG, "Log time granularity '%d' has to be either a " + "divisor or a multiple of 1 second. Changing to " + "'%d'.", + options->LogTimeGranularity, granularity); + set_log_time_granularity(granularity); + } else { + set_log_time_granularity(options->LogTimeGranularity); } ok = 1; |