diff --git a/src/cleo/application.py b/src/cleo/application.py index 4cf435ab..ac9a1638 100644 --- a/src/cleo/application.py +++ b/src/cleo/application.py @@ -538,7 +538,8 @@ def _configure_logging(self, io: IO) -> None: Configures the built-in logging package to write it's output via Cleo's output class. """ handler = CleoHandler(io.output) - handler.setLevel(io.output.verbosity) + handler.setLevel(handler.remap_verbosity(io.output.verbosity)) + root = logging.getLogger() root.addHandler(handler) root.setLevel(handler.level) diff --git a/src/cleo/logging/cleo_handler.py b/src/cleo/logging/cleo_handler.py index a5851c8a..43c8d14e 100644 --- a/src/cleo/logging/cleo_handler.py +++ b/src/cleo/logging/cleo_handler.py @@ -47,16 +47,13 @@ def emit(self, record: logging.LogRecord) -> None: except Exception: self.handleError(record) - def setLevel(self, verbosity: Verbosity) -> None: # noqa: N802 - """ - Set the logging level of this handler. verbosity must be an instance of Cleo's Verbosity enum. - This level is then mapped to it's corresponding `logging` level. - """ - level_mapping = { + @staticmethod + def remap_verbosity(verbosity: Verbosity) -> int: + verbosity_mapping: dict[Verbosity, int] = { Verbosity.QUIET: logging.CRITICAL, # Nothing gets emitted to the output anyway Verbosity.NORMAL: logging.WARNING, Verbosity.VERBOSE: logging.INFO, Verbosity.VERY_VERBOSE: logging.DEBUG, Verbosity.DEBUG: logging.DEBUG, } - return super().setLevel(level_mapping[verbosity]) + return verbosity_mapping[verbosity]