Skip to content

Setting the logger max length for prints #1252

@LC117

Description

@LC117

Hi,
when logging with loguru, messages are truncated by default after 128 symbols, see:

v = v[: max_length - 3] + "..."

While using e.g. @logger.catch(reraise=True) often relevant information is truncated.

Currently, the only way I found to adjust the maximum message length in loguru requires modifying internal attributes, e.g.:

logger._core.handlers[0]._exception_formatter._max_length = 200

This hacky approach relies on internal implementation details.
It would be great to have an officially supported way to set the maximum message length via the public API, such as a configuration parameter when adding a handler or as part of the logger.add() method. Or does this somehow already exist?

For example:
logger.add(sys.stdout, format="{message}", max_message_length=200)

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureRequest for adding a new feature

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions