Improve clarity of logging spew at high verbosity levels.
This commit is contained in:
parent
873fc22cfb
commit
059322b7f8
4 changed files with 31 additions and 0 deletions
2
NEWS
2
NEWS
|
@ -1,4 +1,6 @@
|
||||||
1.1.9.dev0
|
1.1.9.dev0
|
||||||
|
* #16, #38: Support for user-defined hooks before/after backup, or on error.
|
||||||
|
* #33: Improve clarity of logging spew at high verbosity levels.
|
||||||
* #29: Support for using tilde in source directory path to reference home directory.
|
* #29: Support for using tilde in source directory path to reference home directory.
|
||||||
|
|
||||||
1.1.8
|
1.1.8
|
||||||
|
|
|
@ -1,10 +1,15 @@
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
from subprocess import CalledProcessError
|
from subprocess import CalledProcessError
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from borgmatic.borg import check, create, prune
|
from borgmatic.borg import check, create, prune
|
||||||
from borgmatic.config import collect, convert, validate
|
from borgmatic.config import collect, convert, validate
|
||||||
|
from borgmatic.verbosity import VERBOSITY_SOME, VERBOSITY_LOTS, verbosity_to_log_level
|
||||||
|
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
LEGACY_CONFIG_PATH = '/etc/borgmatic/config'
|
LEGACY_CONFIG_PATH = '/etc/borgmatic/config'
|
||||||
|
@ -75,13 +80,17 @@ def parse_arguments(*arguments):
|
||||||
def main(): # pragma: no cover
|
def main(): # pragma: no cover
|
||||||
try:
|
try:
|
||||||
args = parse_arguments(*sys.argv[1:])
|
args = parse_arguments(*sys.argv[1:])
|
||||||
|
logging.basicConfig(level=verbosity_to_log_level(args.verbosity), format='%(message)s')
|
||||||
|
|
||||||
config_filenames = tuple(collect.collect_config_filenames(args.config_paths))
|
config_filenames = tuple(collect.collect_config_filenames(args.config_paths))
|
||||||
|
logger.debug('Ensuring legacy configuration is upgraded')
|
||||||
convert.guard_configuration_upgraded(LEGACY_CONFIG_PATH, config_filenames)
|
convert.guard_configuration_upgraded(LEGACY_CONFIG_PATH, config_filenames)
|
||||||
|
|
||||||
if len(config_filenames) == 0:
|
if len(config_filenames) == 0:
|
||||||
raise ValueError('Error: No configuration files found in: {}'.format(' '.join(args.config_paths)))
|
raise ValueError('Error: No configuration files found in: {}'.format(' '.join(args.config_paths)))
|
||||||
|
|
||||||
for config_filename in config_filenames:
|
for config_filename in config_filenames:
|
||||||
|
logger.info('{}: Parsing configuration file'.format(config_filename))
|
||||||
config = validate.parse_configuration(config_filename, validate.schema_filename())
|
config = validate.parse_configuration(config_filename, validate.schema_filename())
|
||||||
(location, storage, retention, consistency) = (
|
(location, storage, retention, consistency) = (
|
||||||
config.get(section_name, {})
|
config.get(section_name, {})
|
||||||
|
@ -93,8 +102,10 @@ def main(): # pragma: no cover
|
||||||
|
|
||||||
for repository in location['repositories']:
|
for repository in location['repositories']:
|
||||||
if args.prune:
|
if args.prune:
|
||||||
|
logger.info('{}: Pruning archives'.format(repository))
|
||||||
prune.prune_archives(args.verbosity, repository, retention, remote_path=remote_path)
|
prune.prune_archives(args.verbosity, repository, retention, remote_path=remote_path)
|
||||||
if args.create:
|
if args.create:
|
||||||
|
logger.info('{}: Creating archive'.format(repository))
|
||||||
create.create_archive(
|
create.create_archive(
|
||||||
args.verbosity,
|
args.verbosity,
|
||||||
repository,
|
repository,
|
||||||
|
@ -102,6 +113,7 @@ def main(): # pragma: no cover
|
||||||
storage,
|
storage,
|
||||||
)
|
)
|
||||||
if args.check:
|
if args.check:
|
||||||
|
logger.info('{}: Running consistency checks'.format(repository))
|
||||||
check.check_archives(args.verbosity, repository, consistency, remote_path=remote_path)
|
check.check_archives(args.verbosity, repository, consistency, remote_path=remote_path)
|
||||||
except (ValueError, OSError, CalledProcessError) as error:
|
except (ValueError, OSError, CalledProcessError) as error:
|
||||||
print(error, file=sys.stderr)
|
print(error, file=sys.stderr)
|
||||||
|
|
|
@ -38,6 +38,8 @@ def parse_configuration(config_filename, schema_filename):
|
||||||
Raise FileNotFoundError if the file does not exist, PermissionError if the user does not
|
Raise FileNotFoundError if the file does not exist, PermissionError if the user does not
|
||||||
have permissions to read the file, or Validation_error if the config does not match the schema.
|
have permissions to read the file, or Validation_error if the config does not match the schema.
|
||||||
'''
|
'''
|
||||||
|
logging.getLogger('pykwalify').setLevel(logging.ERROR)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
config = yaml.round_trip_load(open(config_filename))
|
config = yaml.round_trip_load(open(config_filename))
|
||||||
schema = yaml.round_trip_load(open(schema_filename))
|
schema = yaml.round_trip_load(open(schema_filename))
|
||||||
|
|
|
@ -1,2 +1,17 @@
|
||||||
|
import logging
|
||||||
|
|
||||||
|
|
||||||
VERBOSITY_SOME = 1
|
VERBOSITY_SOME = 1
|
||||||
VERBOSITY_LOTS = 2
|
VERBOSITY_LOTS = 2
|
||||||
|
|
||||||
|
|
||||||
|
def verbosity_to_log_level(verbosity):
|
||||||
|
'''
|
||||||
|
Given a borgmatic verbosity value, return the corresponding Python log level.
|
||||||
|
'''
|
||||||
|
return {
|
||||||
|
VERBOSITY_SOME: logging.INFO,
|
||||||
|
VERBOSITY_LOTS: logging.DEBUG,
|
||||||
|
}.get(verbosity, logging.ERROR)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue