Closed vikramsubramanian closed 3 weeks ago
When using the logger
, Loguru will try to format the message according to provided arguments. The logger
was initialized intended to be used this way:
value = 42
logger.info("Some message with value: {}", value)
Internally, it roughly calls:
message.format(*args, **kwargs)
In your case, due to text
begin a JSON-serialized message, the formatting raises an exception because it wasn't intended to be formatted but Loguru isn't aware of that.
As a workaround, you can use bind()
to structure your message this way:
logger.bind(name="special").info(text)
In future version, the automatic formatting will likely be removed in favor of f-strings.
logger.info("xxx", name="special") can achieve the effect, but when print json format string by this way will causing an KeyError.