Skip to content

Commit

Permalink
Add log level NONE and deprecate quiet
Browse files Browse the repository at this point in the history
Fixes #154
  • Loading branch information
asmacdo committed Aug 21, 2024
1 parent cb71d9c commit 6ed35d4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/con_duct/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions test/test_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 6ed35d4

Please sign in to comment.