From 6ed35d4d3629f279a301da7acf9924bfbb682149 Mon Sep 17 00:00:00 2001 From: Austin Macdonald Date: Wed, 21 Aug 2024 12:26:41 -0500 Subject: [PATCH 1/5] 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( From e3c5fb9f36bb72d900f3202e1d1025fdf3f072bb Mon Sep 17 00:00:00 2001 From: Austin Macdonald Date: Wed, 21 Aug 2024 13:21:39 -0500 Subject: [PATCH 2/5] [DATALAD RUNCMD] Autoupdate readme === Do not change lines below === { "chain": [], "cmd": "./.update-readme-help.py", "exit": 0, "extra_inputs": [], "inputs": [], "outputs": [], "pwd": "." } ^^^ Do not change lines above ^^^ --- README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 724d645a..6aa50c97 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ A process wrapper script that monitors the execution of a command. usage: duct [-h] [--version] [-p OUTPUT_PREFIX] [--summary-format SUMMARY_FORMAT] [--clobber] - [-l {CRITICAL,ERROR,WARNING,INFO,DEBUG}] [-q] + [-l {CRITICAL,ERROR,WARNING,INFO,DEBUG,NONE}] [-q] [--sample-interval SAMPLE_INTERVAL] [--report-interval REPORT_INTERVAL] [-c {all,none,stdout,stderr}] [-o {all,none,stdout,stderr}] @@ -66,10 +66,11 @@ options: {num_samples} Reports Written: {num_reports} ) --clobber Replace log files if they already exist. (default: False) - -l {CRITICAL,ERROR,WARNING,INFO,DEBUG}, --log_level {CRITICAL,ERROR,WARNING,INFO,DEBUG} - Log level from duct operation. (default: INFO) - -q, --quiet Disable duct logging output (to stderr) (default: - False) + -l {CRITICAL,ERROR,WARNING,INFO,DEBUG,NONE}, --log_level {CRITICAL,ERROR,WARNING,INFO,DEBUG,NONE} + Log level from duct operation, use NONE to disable + duct output to stderr. (default: INFO) + -q, --quiet [deprecated, use log level NONE] Disable duct logging + output (to stderr) (default: False) --sample-interval SAMPLE_INTERVAL, --s-i SAMPLE_INTERVAL Interval in seconds between status checks of the running process. Sample interval must be less than or From 0db3e288f35f8538bc8bc5ac148e7ae66a3bb7fa Mon Sep 17 00:00:00 2001 From: Austin Macdonald Date: Wed, 21 Aug 2024 13:54:49 -0500 Subject: [PATCH 3/5] Order from nothing to most Co-authored-by: Yaroslav Halchenko --- src/con_duct/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/con_duct/__main__.py b/src/con_duct/__main__.py index 8a244948..a7a8eedf 100644 --- a/src/con_duct/__main__.py +++ b/src/con_duct/__main__.py @@ -512,7 +512,7 @@ def from_argv( "-l", "--log_level", default=DEFAULT_LOG_LEVEL, - choices=("CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG", "NONE"), + choices=("NONE", "CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG"), help="Log level from duct operation, use NONE to disable duct output to stderr.", ) parser.add_argument( From b6f214d053412d398fd644f929b87498269da914 Mon Sep 17 00:00:00 2001 From: Austin Macdonald Date: Wed, 21 Aug 2024 14:09:22 -0500 Subject: [PATCH 4/5] Update src/con_duct/__main__.py Co-authored-by: Yaroslav Halchenko --- src/con_duct/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/con_duct/__main__.py b/src/con_duct/__main__.py index a7a8eedf..98a2cde2 100644 --- a/src/con_duct/__main__.py +++ b/src/con_duct/__main__.py @@ -513,7 +513,7 @@ def from_argv( "--log_level", default=DEFAULT_LOG_LEVEL, choices=("NONE", "CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG"), - help="Log level from duct operation, use NONE to disable duct output to stderr.", + help="Level of log output to stderr, use NONE to entirely disable.", ) parser.add_argument( "-q", From 4fd03fabef8338f7cb830b590709ebf981212c67 Mon Sep 17 00:00:00 2001 From: Austin Macdonald Date: Wed, 21 Aug 2024 14:13:32 -0500 Subject: [PATCH 5/5] [DATALAD RUNCMD] Autoupdate readme === Do not change lines below === { "chain": [], "cmd": "./.update-readme-help.py", "exit": 0, "extra_inputs": [], "inputs": [], "outputs": [], "pwd": "." } ^^^ Do not change lines above ^^^ --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6aa50c97..fb773ac0 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ A process wrapper script that monitors the execution of a command. usage: duct [-h] [--version] [-p OUTPUT_PREFIX] [--summary-format SUMMARY_FORMAT] [--clobber] - [-l {CRITICAL,ERROR,WARNING,INFO,DEBUG,NONE}] [-q] + [-l {NONE,CRITICAL,ERROR,WARNING,INFO,DEBUG}] [-q] [--sample-interval SAMPLE_INTERVAL] [--report-interval REPORT_INTERVAL] [-c {all,none,stdout,stderr}] [-o {all,none,stdout,stderr}] @@ -66,9 +66,9 @@ options: {num_samples} Reports Written: {num_reports} ) --clobber Replace log files if they already exist. (default: False) - -l {CRITICAL,ERROR,WARNING,INFO,DEBUG,NONE}, --log_level {CRITICAL,ERROR,WARNING,INFO,DEBUG,NONE} - Log level from duct operation, use NONE to disable - duct output to stderr. (default: INFO) + -l {NONE,CRITICAL,ERROR,WARNING,INFO,DEBUG}, --log_level {NONE,CRITICAL,ERROR,WARNING,INFO,DEBUG} + Level of log output to stderr, use NONE to entirely + disable. (default: INFO) -q, --quiet [deprecated, use log level NONE] Disable duct logging output (to stderr) (default: False) --sample-interval SAMPLE_INTERVAL, --s-i SAMPLE_INTERVAL