Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add log level NONE and deprecate quiet #159

Merged
merged 5 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}]
Expand Down Expand Up @@ -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
Expand Down
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
Loading