Skip to content

Commit ed1c56c

Browse files
committed
Make it possibly to disable system logging (#20)
1 parent 47e10cd commit ed1c56c

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

README.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,9 @@ intended you have no right to complain ;-).
217217
"``-u``, ``--use-sudo``","Enable the use of ""sudo"" to rotate backups in directories that are not
218218
readable and/or writable for the current user (or the user logged in to a
219219
remote system over SSH)."
220+
"``-S``, ``--syslog=CHOICE``","Explicitly enable or disable system logging instead of letting the program
221+
figure out what to do. The values '1', 'yes', 'true' and 'on' enable system
222+
logging whereas the values '0', 'no', 'false' and 'off' disable it."
220223
"``-f``, ``--force``","If a sanity check fails an error is reported and the program aborts. You
221224
can use ``--force`` to continue with backup rotation instead. Sanity checks
222225
are done to ensure that the given DIRECTORY exists, is readable and is

rotate_backups/cli.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# rotate-backups: Simple command line interface for backup rotation.
22
#
33
# Author: Peter Odding <peter@peterodding.com>
4-
# Last Change: February 12, 2020
4+
# Last Change: February 13, 2020
55
# URL: https://github.com/xolox/python-rotate-backups
66

77
"""
@@ -160,6 +160,12 @@
160160
readable and/or writable for the current user (or the user logged in to a
161161
remote system over SSH).
162162
163+
-S, --syslog=CHOICE
164+
165+
Explicitly enable or disable system logging instead of letting the program
166+
figure out what to do. The values '1', 'yes', 'true' and 'on' enable system
167+
logging whereas the values '0', 'no', 'false' and 'off' disable it.
168+
163169
-f, --force
164170
165171
If a sanity check fails an error is reported and the program aborts. You
@@ -194,8 +200,10 @@
194200

195201
# External dependencies.
196202
import coloredlogs
203+
from coloredlogs import WINDOWS
204+
from coloredlogs.syslog import enable_system_logging
197205
from executor import validate_ionice_class
198-
from humanfriendly import parse_path, pluralize
206+
from humanfriendly import coerce_boolean, parse_path, pluralize
199207
from humanfriendly.terminal import usage
200208
from verboselogs import VerboseLogger
201209

@@ -213,21 +221,22 @@
213221

214222
def main():
215223
"""Command line interface for the ``rotate-backups`` program."""
216-
coloredlogs.install(syslog=True)
224+
coloredlogs.install()
217225
# Command line option defaults.
218226
rotation_scheme = {}
219227
kw = dict(include_list=[], exclude_list=[])
220228
parallel = False
221229
use_sudo = False
230+
use_syslog = (not WINDOWS)
222231
# Internal state.
223232
selected_locations = []
224233
# Parse the command line arguments.
225234
try:
226-
options, arguments = getopt.getopt(sys.argv[1:], 'M:H:d:w:m:y:I:x:jpri:c:r:uC:fnvqh', [
235+
options, arguments = getopt.getopt(sys.argv[1:], 'M:H:d:w:m:y:I:x:jpri:c:C:uS:fnvqh', [
227236
'minutely=', 'hourly=', 'daily=', 'weekly=', 'monthly=', 'yearly=',
228237
'include=', 'exclude=', 'parallel', 'prefer-recent', 'relaxed',
229-
'ionice=', 'config=', 'removal-command=', 'use-sudo', 'force',
230-
'dry-run', 'verbose', 'quiet', 'help',
238+
'ionice=', 'config=', 'removal-command=', 'use-sudo', 'syslog=',
239+
'force', 'dry-run', 'verbose', 'quiet', 'help',
231240
])
232241
for option, value in options:
233242
if option in ('-M', '--minutely'):
@@ -263,6 +272,8 @@ def main():
263272
kw['removal_command'] = removal_command
264273
elif option in ('-u', '--use-sudo'):
265274
use_sudo = True
275+
elif option in ('-S', '--syslog'):
276+
use_syslog = coerce_boolean(value)
266277
elif option in ('-f', '--force'):
267278
kw['force'] = True
268279
elif option in ('-n', '--dry-run'):
@@ -277,6 +288,8 @@ def main():
277288
return
278289
else:
279290
assert False, "Unhandled option! (programming error)"
291+
if use_syslog:
292+
enable_system_logging()
280293
if rotation_scheme:
281294
logger.verbose("Rotation scheme defined on command line: %s", rotation_scheme)
282295
if arguments:

0 commit comments

Comments
 (0)