Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
Add a 'length' argument to the 'add' function supporting better_excep…
…tion's MAX_LENGTH
  • Loading branch information
daniel347x committed Oct 26, 2024
commit 44dd6281a85691719e70dd338f8e459c267e220b
1 change: 1 addition & 0 deletions loguru/_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def env(key, type_, default=None):
LOGURU_ENQUEUE = env("LOGURU_ENQUEUE", bool, False)
LOGURU_CONTEXT = env("LOGURU_CONTEXT", str, None)
LOGURU_CATCH = env("LOGURU_CATCH", bool, True)
LOGURU_LENGTH = env("LOGURU_LENGTH", int, 128)

LOGURU_TRACE_NO = env("LOGURU_TRACE_NO", int, 5)
LOGURU_TRACE_COLOR = env("LOGURU_TRACE_COLOR", str, "<cyan><bold>")
Expand Down
6 changes: 6 additions & 0 deletions loguru/_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ def add(
enqueue=_defaults.LOGURU_ENQUEUE,
context=_defaults.LOGURU_CONTEXT,
catch=_defaults.LOGURU_CATCH,
length=_defaults.LOGURU_LENGTH,
**kwargs
):
r"""Add a handler sending log messages to a sink adequately configured.
Expand Down Expand Up @@ -290,6 +291,10 @@ def add(
Whether errors occurring while sink handles logs messages should be automatically
caught. If ``True``, an exception message is displayed on |sys.stderr| but the exception
is not propagated to the caller, preventing your app to crash.
length : |int|, optional
This controls the maximum line length of every line in the exception backtrace,
mapping directly to the better_exceptions library's MAX_LENGTH value.
Set to None for no limit.
**kwargs
Additional parameters that are only valid to configure a coroutine or file sink (see
below).
Expand Down Expand Up @@ -984,6 +989,7 @@ def add(
backtrace=backtrace,
hidden_frames_filename=self.catch.__code__.co_filename,
prefix=exception_prefix,
max_length=length,
)

handler = Handler(
Expand Down