Skip to content
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add exception_formatter kwarg to logger.add
  • Loading branch information
blueyed committed Apr 9, 2019
commit 1c7c7a41af21058d10f49603ee434a932aafb96b
20 changes: 13 additions & 7 deletions loguru/_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

start_time = now()

UNSET = object()


class Logger:
"""An object to dispatch logging messages to configured handlers.
Expand Down Expand Up @@ -163,6 +165,7 @@ def add(
diagnose=_defaults.LOGURU_DIAGNOSE,
enqueue=_defaults.LOGURU_ENQUEUE,
catch=_defaults.LOGURU_CATCH,
exception_formatter=UNSET,
**kwargs
):
r"""Add a handler sending log messages to a sink adequately configured.
Expand Down Expand Up @@ -201,6 +204,8 @@ def add(
Whether or not errors occurring while sink handles logs messages should be caught or
not. If ``True``, an exception message is displayed on |sys.stderr| but the exception is
not propagated to the caller, preventing your app to crash.
exception_formatter : |ExceptionFormatter|, optional
By default ``loguru._better_exceptions.ExceptionFormatter`` is used.
**kwargs
Additional parameters that will be passed to the sink while creating it or while
logging messages (the exact behavior depends on the sink type).
Expand Down Expand Up @@ -762,13 +767,14 @@ def filter_func(r):
handler_id = next(self._handlers_count)
colors = [lvl.color for lvl in self._levels.values()] + [""]

exception_formatter = ExceptionFormatter(
colorize=colorize,
encoding=encoding,
diagnose=diagnose,
backtrace=backtrace,
hidden_frames_filename=self.catch.__code__.co_filename,
)
if exception_formatter is UNSET:
exception_formatter = ExceptionFormatter(
colorize=colorize,
encoding=encoding,
diagnose=diagnose,
backtrace=backtrace,
hidden_frames_filename=self.catch.__code__.co_filename,
)

handler = Handler(
writer=writer,
Expand Down