From 6ed35d4d3629f279a301da7acf9924bfbb682149 Mon Sep 17 00:00:00 2001 From: Austin Macdonald Date: Wed, 21 Aug 2024 12:26:41 -0500 Subject: [PATCH] Add log level NONE and deprecate quiet Fixes https://github.com/con/duct/issues/154 --- src/con_duct/__main__.py | 11 ++++++----- test/test_execution.py | 11 +++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/con_duct/__main__.py b/src/con_duct/__main__.py index 3aa942c7..8a244948 100644 --- a/src/con_duct/__main__.py +++ b/src/con_duct/__main__.py @@ -512,14 +512,14 @@ def from_argv( "-l", "--log_level", default=DEFAULT_LOG_LEVEL, - choices=("CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG"), - help="Log level from duct operation.", + choices=("CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG", "NONE"), + help="Log level from duct operation, use NONE to disable duct output to stderr.", ) parser.add_argument( "-q", "--quiet", action="store_true", - help="Disable duct logging output (to stderr)", + help="[deprecated, use log level NONE] Disable duct logging output (to stderr)", ) parser.add_argument( "--sample-interval", @@ -737,9 +737,10 @@ def execute(args: Arguments) -> int: Returns exit code of the executed process. """ - lgr.setLevel(args.log_level) - if args.quiet: + if args.log_level == "NONE" or args.quiet: lgr.disabled = True + else: + lgr.setLevel(args.log_level) log_paths = LogPaths.create(args.output_prefix, pid=os.getpid()) log_paths.prepare_paths(args.clobber, args.capture_outputs) stdout, stderr = prepare_outputs(args.capture_outputs, args.outputs, log_paths) diff --git a/test/test_execution.py b/test/test_execution.py index 904a1df5..a0d1cc4c 100644 --- a/test/test_execution.py +++ b/test/test_execution.py @@ -151,6 +151,17 @@ def test_outputs_none_quiet( # But nothing new to the log assert caplog.text == caplog_text1 + # log_level NONE should have the same behavior as quiet + args.log_level = "NONE" + args.quiet = False + args.clobber = True # to avoid the file already exists error + assert execute(args) == 0 + r3 = capsys.readouterr() + # Still have all the outputs + assert r1 == r3 + # But nothing new to the log + assert caplog.text == caplog_text1 + def test_exit_before_first_sample(temp_output_dir: str) -> None: args = Arguments.from_argv(