Skip to content

Commit

Permalink
Cleaned up verbosity remapping system
Browse files Browse the repository at this point in the history
  • Loading branch information
dylan-robins committed Jan 4, 2025
1 parent 0846085 commit 18c3d9b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/cleo/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 4 additions & 7 deletions src/cleo/logging/cleo_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

0 comments on commit 18c3d9b

Please sign in to comment.