Finish adding configurable log rotation

* Update log backupCount name and description.

* Add additional error handling to --log-backups

* test --log-backups flag

* Pass log_backups value to RotatingFileHandler

* Test that log_backups is properly used

* add _test_success_common

* Add test_success_with_rollover

* Add test_success_without_rollover

* mock stderr in cli tests

* Set log_backups in PostArgParseSetupTest

* Rename "log backups" to "max log backups"
This commit is contained in:
Brad Warren
2017-07-11 21:14:18 -05:00
parent fad1a4b576
commit a7a8e060e3
4 changed files with 65 additions and 15 deletions
+29 -9
View File
@@ -850,15 +850,11 @@ def prepare_and_parse_args(plugins, args, detect_defaults=False): # pylint: dis
None, "-t", "--text", dest="text_mode", action="store_true",
help=argparse.SUPPRESS)
helpful.add(
# Note, 1 is subtracted from max_log_count in certbot/main.py
#> to correct an off by one error.
[None, "paths"],
"--max-log-count", dest="max_log_count",
type=int, default=1000,
help="Specifies the maximum number of certbot log files "
"that will be kept. 0 disables log rotation. 1 causes "
"only the log from the most recent run to be kept. "
"2+ enables log rotation at start of certbot execution.")
None, "--max-log-backups", type=nonnegative_int, default=1000,
help="Specifies the maximum number of backup logs that should "
"be kept by Certbot's built in log rotation. Setting this "
"flag to 0 disables log rotation entirely, causing "
"Certbot to always append to the same log file.")
helpful.add(
[None, "automation", "run", "certonly"], "-n", "--non-interactive", "--noninteractive",
dest="noninteractive_mode", action="store_true",
@@ -1385,3 +1381,27 @@ class _RenewHookAction(argparse.Action):
raise argparse.ArgumentError(
self, "conflicts with --deploy-hook value")
namespace.renew_hook = values
def nonnegative_int(value):
"""Converts value to an int and checks that it is not negative.
This function should used as the type parameter for argparse
arguments.
:param str value: value provided on the command line
:returns: integer representation of value
:rtype: int
:raises argparse.ArgumentTypeError: if value isn't a non-negative integer
"""
try:
int_value = int(value)
except ValueError:
raise argparse.ArgumentTypeError("value must be an integer")
if int_value < 0:
raise argparse.ArgumentTypeError("value must be non-negative")
return int_value