replaced "log_as_task" with "log_record"

This commit is contained in:
palto42 2019-12-21 12:26:31 +01:00
parent 3b9b860c29
commit 64d78e2657
1 changed files with 40 additions and 27 deletions

View File

@ -30,11 +30,6 @@ logger = logging.getLogger(__name__)
LEGACY_CONFIG_PATH = '/etc/borgmatic/config'
def log_as_task(level, message):
# Log message with label TASK at specified log level
logger.handle(logging.makeLogRecord(dict(levelno=level, levelname='TASK', msg=message)))
def run_configuration(config_filename, config, arguments):
'''
Given a config filename, the corresponding parsed config dict, and command-line arguments as a
@ -197,7 +192,10 @@ def run_actions(
global_arguments = arguments['global']
dry_run_label = ' (dry run; not making any changes)' if global_arguments.dry_run else ''
if 'init' in arguments:
log_as_task(global_arguments.notice_level, '{}: Initializing repository'.format(repository))
log_record(
levelno=global_arguments.notice_level,
levelname="TASK",
msg='{}: Initializing repository'.format(repository))
borg_init.initialize_repository(
repository,
storage,
@ -208,9 +206,10 @@ def run_actions(
remote_path=remote_path,
)
if 'prune' in arguments:
log_as_task(
global_arguments.notice_level,
'{}: Pruning archives{}'.format(repository, dry_run_label),
log_record(
levelno=global_arguments.notice_level,
levelname="TASK",
msg='{}: Pruning archives{}'.format(repository, dry_run_label),
)
borg_prune.prune_archives(
global_arguments.dry_run,
@ -222,9 +221,10 @@ def run_actions(
stats=arguments['prune'].stats,
)
if 'create' in arguments:
log_as_task(
global_arguments.notice_level,
'{}: Creating archive{}'.format(repository, dry_run_label),
log_record(
levelno=global_arguments.notice_level,
levelname="TASK",
msg='{}: Creating archive{}'.format(repository, dry_run_label),
)
json_output = borg_create.create_archive(
global_arguments.dry_run,
@ -240,8 +240,10 @@ def run_actions(
if json_output:
yield json.loads(json_output)
if 'check' in arguments and checks.repository_enabled_for_checks(repository, consistency):
log_as_task(
global_arguments.notice_level, '{}: Running consistency checks'.format(repository)
log_record(
levelno=global_arguments.notice_level,
levelname="TASK",
msg='{}: Running consistency checks'.format(repository)
)
borg_check.check_archives(
repository,
@ -256,9 +258,10 @@ def run_actions(
if arguments['extract'].repository is None or validate.repositories_match(
repository, arguments['extract'].repository
):
log_as_task(
global_arguments.notice_level,
'{}: Extracting archive {}'.format(repository, arguments['extract'].archive),
log_record(
levelno=global_arguments.notice_level,
levelname="TASK",
msg='{}: Extracting archive {}'.format(repository, arguments['extract'].archive),
)
borg_extract.extract_archive(
global_arguments.dry_run,
@ -298,9 +301,10 @@ def run_actions(
if arguments['restore'].repository is None or validate.repositories_match(
repository, arguments['restore'].repository
):
log_as_task(
global_arguments.notice_level,
'{}: Restoring databases from archive {}'.format(
log_record(
levelno=global_arguments.notice_level,
levelname="TASK",
msg='{}: Restoring databases from archive {}'.format(
repository, arguments['restore'].archive
),
)
@ -362,7 +366,11 @@ def run_actions(
if arguments['list'].repository is None or validate.repositories_match(
repository, arguments['list'].repository
):
log_as_task(global_arguments.notice_level, '{}: Listing archives'.format(repository))
log_record(
levelno=global_arguments.notice_level,
levelname="TASK",
msg='{}: Listing archives'.format(repository)
)
json_output = borg_list.list_archives(
repository,
storage,
@ -376,9 +384,10 @@ def run_actions(
if arguments['info'].repository is None or validate.repositories_match(
repository, arguments['info'].repository
):
log_as_task(
global_arguments.notice_level,
'{}: Displaying summary info for archives'.format(repository),
log_record(
levelno=global_arguments.notice_level,
levelname="TASK",
msg='{}: Displaying summary info for archives'.format(repository),
)
json_output = borg_info.display_archives_info(
repository,
@ -531,7 +540,11 @@ def collect_configuration_run_summary_logs(configs, arguments):
# Execute the actions corresponding to each configuration file.
json_results = []
for config_filename, config in configs.items():
log_as_task(notice_level, '{}: Processing configuration file'.format(config_filename))
log_record(
levelno=notice_level,
levelname="TASK",
msg='{}: Processing configuration file'.format(config_filename)
)
results = list(run_configuration(config_filename, config, arguments))
error_logs = tuple(result for result in results if isinstance(result, logging.LogRecord))
@ -544,7 +557,7 @@ def collect_configuration_run_summary_logs(configs, arguments):
yield logging.makeLogRecord(
dict(
levelno=notice_level,
levelname='TASK',
levelname='INFO',
msg='{}: Successfully ran configuration file'.format(config_filename),
)
)
@ -633,7 +646,7 @@ def main(): # pragma: no cover
for message in ('', 'summary:'):
log_record(
levelno=summary_logs_max_level,
levelname=logging.getLevelName(summary_logs_max_level),
levelname="INFO",
msg=message,
)