From 09f59ad97dc83ea761118e15de212c7e9f1c29d1 Mon Sep 17 00:00:00 2001 From: Soumik Dutta Date: Fri, 12 May 2023 19:05:52 +0530 Subject: [PATCH] disable monitoring hooks if monitoring_log_level is set to DISABLED Signed-off-by: Soumik Dutta --- borgmatic/commands/borgmatic.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/borgmatic/commands/borgmatic.py b/borgmatic/commands/borgmatic.py index 965f393..597868f 100644 --- a/borgmatic/commands/borgmatic.py +++ b/borgmatic/commands/borgmatic.py @@ -36,7 +36,7 @@ from borgmatic.borg import version as borg_version from borgmatic.commands.arguments import parse_arguments from borgmatic.config import checks, collect, convert, validate from borgmatic.hooks import command, dispatch, monitor -from borgmatic.logger import add_custom_log_levels, configure_logging, should_do_markup +from borgmatic.logger import add_custom_log_levels, configure_logging, should_do_markup, DISABLED from borgmatic.signals import configure_signals from borgmatic.verbosity import verbosity_to_log_level @@ -70,6 +70,7 @@ def run_configuration(config_filename, config, arguments): error_repository = '' using_primary_action = {'create', 'prune', 'compact', 'check'}.intersection(arguments) monitoring_log_level = verbosity_to_log_level(global_arguments.monitoring_verbosity) + monitoring_hooks_are_activated = using_primary_action and monitoring_log_level != DISABLED try: local_borg_version = borg_version.local_borg_version(storage, local_path) @@ -78,7 +79,7 @@ def run_configuration(config_filename, config, arguments): return try: - if using_primary_action: + if monitoring_hooks_are_activated: dispatch.call_hooks( 'initialize_monitor', hooks, @@ -87,7 +88,7 @@ def run_configuration(config_filename, config, arguments): monitoring_log_level, global_arguments.dry_run, ) - if using_primary_action: + dispatch.call_hooks( 'ping_monitor', hooks, @@ -165,7 +166,7 @@ def run_configuration(config_filename, config, arguments): error_repository = repository['path'] try: - if using_primary_action: + if monitoring_hooks_are_activated: # send logs irrespective of error dispatch.call_hooks( 'ping_monitor', @@ -185,7 +186,7 @@ def run_configuration(config_filename, config, arguments): if not encountered_error: try: - if using_primary_action: + if monitoring_hooks_are_activated: dispatch.call_hooks( 'ping_monitor', hooks,