[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] [tor/master 2/3] Fix log granularity based on Nick's comments.
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date: Mon, 8 Nov 2010 16:37:20 +0100
Subject: Fix log granularity based on Nick's comments.
Commit: ed45bc198f10f5ea3dbd40514bb5b443802b50aa
Instead of rejecting a value that doesn't divide into 1 second, round to
the nearest divisor of 1 second and warn.
Document that the option only controls the granularity written by Tor to a
file or console log. It 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.
---
doc/tor.1.txt | 5 ++++-
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 5d6a959..f666277 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 1112478..0251ef4 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;
--
1.7.1