Skip to content

Commit 36c2503

Browse files
NaddiNadjasafl
authored andcommitted
fix(cli/loglevel): add force param to log.basicConfig()
According to the docs, the `log.basicConfig()` method does nothing if the root logger already has handlers configured. Apparently this happens before the method is called in the code, and therefore we need the `force` parameter to ensure the configuration is applied. https://docs.python.org/3/library/logging.html#logging.basicConfig Additionally, the call to `basicConfig()` is moved to just after the `parse_args()` call to ensure the configuration is applied for the whole run. Signed-off-by: Nadja Brix Koch <[email protected]>
1 parent 9423a52 commit 36c2503

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/cijoe/cli/cli.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,18 @@ def parse_args():
626626

627627
break
628628

629-
return 0, parser.parse_args()
629+
args = parser.parse_args()
630+
631+
levels = [log.ERROR, log.INFO, log.DEBUG]
632+
log.basicConfig(
633+
format="%(levelname)s:%(module)s:%(funcName)s(): %(message)s",
634+
level=levels[
635+
min(sum(args.log_level), len(levels) - 1) if args.log_level else 0
636+
],
637+
force=True,
638+
)
639+
640+
return 0, args
630641

631642

632643
def main(args=None):
@@ -641,14 +652,6 @@ def main(args=None):
641652
# Running stand-alone script
642653
create_adhoc_workflow(args)
643654

644-
levels = [log.ERROR, log.INFO, log.DEBUG]
645-
log.basicConfig(
646-
format="%(levelname)s:%(module)s:%(funcName)s(): %(message)s",
647-
level=levels[
648-
min(sum(args.log_level), len(levels) - 1) if args.log_level else 0
649-
],
650-
)
651-
652655
if args.resources:
653656
return cli_resources(args)
654657

0 commit comments

Comments
 (0)