loguru icon indicating copy to clipboard operation
loguru copied to clipboard

Setting the logger max length for prints

Open LC117 opened this issue 11 months ago • 1 comments
trafficstars

Hi, when logging with loguru, messages are truncated by default after 128 symbols, see: https://github.com/Delgan/loguru/blob/633016db07e5dff63bc05dd3c4d5aa81b6190700/loguru/_better_exceptions.py#L346 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!

LC117 avatar Dec 06 '24 11:12 LC117