-
Notifications
You must be signed in to change notification settings - Fork 704
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question on the adequate behavior of formatting color. #57
Comments
This is by design of the # Unrecognized tags are left as-is.
parse("<b><element1></element1></b>") I think it makes sense for Loguru too. I would like the logger to be as permissive as possible about accepted formats. If for some unknown reason an user wish to use xml tags within the logs format or set In case of incorrect color like in your example, the raw tags appearing in the logs make it quite immediate to notice and easy to fix. However, I agree, this may surprise the user as it's most of the time unintentional and hence an error. It would be more elegant to inform the user by raising an exception. I think it would be possible to have the best of both worlds by adding a way to escape xml tags. So, the format stay permissive by allowing user to log raw tags if he wants, otherwise not escaped tags are parsed as color markups and raise an error if they are not recognized. As we are about color markups, I have been thinking of replacing them with something else. Basically, I don't like much mixing xml tags in the middle of Python formatting, I find it too verbose for hexadecimal colors like I'm experimenting with something like: class Color:
def __init__(self, ansi):
self.ansi = ansi
def __format__(self, spec):
return self.ansi + spec + "\x1b[0m"
color = {"green": Color("\033[92m"), "blue": Color("\033[94m")}
record = dict(message="Foo", level="DEBUG", color=color)
print("{color[green]:{level}} - {color[blue]:{message}}".format(**record)) I'm not convinced this looks much better, but at least it allows formatting to be fully handled by well-known Python |
Hello, |
Yep, this looks too much nested with the I'm open to any good suggestion. Basically, we just need a way to escape the xml tags, or an alternative way to define colors in format. |
I have been thinking to something like this: format = "<green:{time}> - <level:{level}> - <blue:{message}>" Color markups could be escaped by doubling the signs, like for |
In my eyes, your new idea looks much better than the original one!! :) Not only the format gets shorter, but also is the better structure for raising exception. So, I would say this could give better impression to users in terms of interface. What do you think? :D |
Great, I'm pleased you like it. 😄 This feels somehow "weird" because this doesn't use a well-known markup language syntax. But overall, this reduces verbosity and allows explicit exceptions to be raised, so it's probably worth it. |
I modified the parsing of colors tags so it raises adequate errors if a tag name can't be parsed. I will be effective in the next Contrary to what I suggested in my previous messages, I did not implement the
So, I stayed with the
|
Hello,
I have just found that the following code snippet,
results in
It seems that tags(ex.<Green></Green>) which are not properly parsed by
ansimarkup
library are sent to sink without any blockers.Is it the expected behavior when it was designed?
or should we raise an exception for this? :)
In my eyes, if color tags cannot be properly converted, it should give feedback to users instead of letting them recognize it after logs are recorded in sinks. :)
What do you think?
The text was updated successfully, but these errors were encountered: