Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a 'length' argument to the 'add' function supporting "max_length" #1224

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
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
Loading