loguru
loguru copied to clipboard
loguru breaks if logging message contains {
a log beginning with: "Cannot initialise stack with data {'hub_id': ...
makes loguru fail:
File "/env/local/lib/python3.7/site-packages/pltlib/log.py", line 86, in error
return logger.error(*args, **kwargs)
│ │ │ └ {'tracking_id': '#'}
│ │ └ ("Cannot initialise stack with data {'hub_id': ...
│ └ <function Logger.error at 0x3e23c83e3680>
└ <loguru.logger handlers=[(id=0, level=10, sink=<_io.TextIOWrapper encoding='utf-8'>)]>
This happens because of the automatic formatting. Loguru will call message.format(*args, **kwargs) with message being "Cannot initialise stack with data {'hub_id': ..." in your case. It won't work. Do you need to call logger.error() this way, with *args unpacking?
A possible workaround is to replace **kwargs with bind() if you intend to capture the data but not format it:
message, *_ = args
logger.bind(**kwargs).error(message)
In the end, this issue seems similar to #318. I will add a new method allowing to disable formatting.