loguru
loguru copied to clipboard
Raw message not available for the patcher function
Hey, I was about to use my patcher function to implement styles that would let me easily manage the appearance of the structure of complex messages. Unfortunately, I realized that the markups are stripped away already from the message record and I can't do that. Is it possible to ensure that the record passed to the patcher function has the raw message, untouched version from the user?
I do believe it may be a bug, because according to the documentation: the "message" field is "The logged message (not yet formatted)".
Python 3.8.12 loguru 0.6.0 Ubuntu 20.04.3 LTS
How to reproduce:
from loguru import logger
logger = logger.patch(lambda record: print("Message:", record['message']))
logger.opt(colors=True).info("<red>Test</>")
Result:
Message: test 2022-02-17 17:56:04.936 | INFO | main:
:1 - test
The logged message is red as expected, but the "message" field is altered already.
Also, I can't use my own tags, as the exception is being thrown before the patcher receives the record:
logger.opt(colors=True).info("<STYLE>test</>")
ValueError: Tag "<STYLE>" does not corespond to any known ansi directive, make sure you did not misspelled it (or prepend '' to escape it)
Hi @oppressed-artist.
For now, this is unfortunately not possible. Color tags are stripped away for technical and practical reasons. However, in the future I would like to allow to configure the message formatting. This is an improvement that has been requested several times already and that I plan to implement, but I don't know yet how exactly.