Add option to mute test logs

This commit is contained in:
mike 2024-06-22 15:31:31 -07:00
parent 403531d7f0
commit 3c4ed5f792
3 changed files with 33 additions and 6 deletions

View File

@ -31,13 +31,17 @@ class BackupRotator:
config_paths: [Path] = None, config_paths: [Path] = None,
debug: bool = False, debug: bool = False,
systemd: bool = False, systemd: bool = False,
write_to_syslog: bool = False write_to_syslog: bool = False,
do_test_logs: bool = True,
): ):
self.__do_test_logs = do_test_logs
self.__logger = Logger( self.__logger = Logger(
name=type(self).__name__, name=type(self).__name__,
debug=debug, debug=debug,
systemd=systemd, systemd=systemd,
write_to_syslog=write_to_syslog, write_to_syslog=write_to_syslog,
do_test_logs=do_test_logs,
) )
self.__config = Config( self.__config = Config(

View File

@ -12,13 +12,15 @@ class Logger:
name: str, name: str,
debug: bool = False, debug: bool = False,
write_to_syslog: bool = False, write_to_syslog: bool = False,
systemd: bool = False systemd: bool = False,
do_test_logs: bool = True,
): ):
self.__name = name self.__name = name
self.__debug = debug self.__debug = debug
self.__write_to_syslog = write_to_syslog self.__write_to_syslog = write_to_syslog
self.__systemd = systemd self.__systemd = systemd
self.__do_test_logs = do_test_logs
self._init_logger() self._init_logger()
@ -73,10 +75,11 @@ class Logger:
self.__logger.addHandler(handler) self.__logger.addHandler(handler)
# This is annoying inside cron # This is annoying inside cron
self.debug("Test debug log") if self.__do_test_logs:
self.info("Test info log") self.debug("Test debug log")
self.warn("Test warn log") self.info("Test info log")
self.error("Test error log") self.warn("Test warn log")
self.error("Test error log")
def debug(self, s): def debug(self, s):
self.__logger.debug(s) self.__logger.debug(s)

20
main.py
View File

@ -42,6 +42,25 @@ def main():
) )
) )
parser.add_argument(
"--no-test-logs",
default=True,
dest="do_test_logs",
action="store_false",
help=(
"Pass if you do not want to see test logs for all log levels."
)
)
parser.add_argument(
"--test-logs",
default=True,
dest="do_test_logs",
action="store_true",
help=(
"Pass if you want to see test logs for all log levels."
)
)
parser.add_argument( parser.add_argument(
"--config", "-c", "--config", "-c",
dest="config_paths", dest="config_paths",
@ -68,6 +87,7 @@ def main():
debug=args.debug, debug=args.debug,
systemd=args.systemd, systemd=args.systemd,
write_to_syslog=args.write_to_syslog, write_to_syslog=args.write_to_syslog,
do_test_logs=args.do_test_logs,
) )
rotator.run( rotator.run(
global_dry_run=args.global_dry_run global_dry_run=args.global_dry_run