mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-10 13:13:44 +01:00
Fix log granularity based on Nick's comments.
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.
This commit is contained in:
parent
8c5ba9388b
commit
ed45bc198f
@ -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.
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user