Skip to content

Commit

Permalink
refactor: small tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
fbdtemme committed Jan 30, 2024
1 parent 88ea7d6 commit 208bccb
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/pixelator/cli/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@

from pixelator.types import PathType

root_logger = logging.getLogger()
pixelator_root_logger = logging.getLogger("pixelator")


# Silence deprecation warnings
warnings.simplefilter("ignore", category=NumbaDeprecationWarning)
Expand All @@ -42,9 +39,6 @@
# Click logging
# ------------------------------------------------------------

LOGGER_KEY = __name__ + ".logger"
DEFAULT_LEVEL = logging.INFO


class StyleDict(typing.TypedDict):
"""Style dictionary for kwargs to `click.style`."""
Expand Down Expand Up @@ -106,21 +100,23 @@ class ClickHandler(logging.Handler):
Messages are forwarded to stdout using `click.echo`.
"""

def __init__(self, *args, use_stderr: bool = True, **kwargs):
def __init__(self, level: int = 0, use_stderr: bool = True):
"""Initialize the click handler.
:param level: The logging level.
:param use_stderr: Log to sys.stderr instead of sys.stdout.
:param args: The arguments to pass to the base class.
:param kwargs: The keyword arguments to pass to base class.
"""
super().__init__(*args, **kwargs)
super().__init__(level=level)
self._use_stderr = use_stderr

def emit(self, record: logging.LogRecord) -> None:
"""Do whatever it takes to actually log the specified logging record."""
"""Do whatever it takes to actually log the specified logging record.
:param record: The record to log.
"""
try:
msg = self.format(record)
click.echo(msg, file=sys.stdout, err=self._use_stderr)
click.echo(msg, err=self._use_stderr)
except Exception:
self.handleError(record)

Expand Down Expand Up @@ -261,6 +257,8 @@ def _listener_process_main(

def handle_unhandled_exception(exc_type, exc_value, exc_traceback):
"""Handle "unhandled" exceptions."""
pixelator_root_logger = logging.getLogger("pixelator")

if issubclass(exc_type, KeyboardInterrupt):
# Will call default excepthook
sys.__excepthook__(exc_type, exc_value, exc_traceback)
Expand Down

0 comments on commit 208bccb

Please sign in to comment.