-
Notifications
You must be signed in to change notification settings - Fork 696
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
No correspondence between string and int level format #209
Comments
Hi @Vedrillan. The way the levels work is indeed slightly different between A level is basically a Level(name='INFO', no=20, color='<bold>', icon='ℹ️') I think what should be used to identify a level is its name, not its number. It's perfectly valid to create a custom level while another one exist with the same Adding constants to reference levels has been discussed, but it doesn't seem much useful to having to type |
After more reading of the code, I indeed see that the levels are identified by their names. This is a strange thing to me, as in my opinion log levels should be identified by both their names and levels. Changing the level or name of a "core" level, such as "INFO", would not make sens as it goes against common logging practices (of things I have used, ruby, php, javascript, syslog). Such changes would just generate confusion. One could consider that developers are free to make "DEBUG" logs appear more critical that "EMERGENCY" but others prefer to capitalize on standards and common practices. I am obviously of second group, and if you are not that is alright, we all have our opinions and they do not have to be similar. In the end I am only hoping for the existing levels to be constant, by their names and levels, across all my projects, to avoid the mess and pain that changing the "standardized level" would generate, but if it is not the philosophy of loguru then be it, I will just have to use something else that fits my requirements. |
So, are you suggesting to actually make the That is, logging with |
In my opinion both The fact that the If someone can change either one of the |
The However, I'm still convinced that a |
The As you said this can not be applied to custom levels otherwise it would lead to issues if several lib created their own levels and end up with a The more the conversation goes the more I understand why the logging system I used do not allow custom levels, to prevents special cases and fragile situations. My opinion is to make core levels |
I do agree that core levels are more than enough, but some people like to use custom levels, so I tried to provide a working solution for their use case. You are talking about preventing special cases: that's one of the main reason I would prefer to avoid implementing any specific behavior for core levels. From my point of view, it's more important to keep the API as simple as possible rather than allowing severity no to be mapped to level. It's easier to say "levels are only identifiable by their name" rather than to explain "levels are identifiable by their name, core levels are identifiable by no too, custom levels can't use core levels no". To be honest, I still don't understand what bothers you about custom level using "core" severity, and I also don't understand why you think it's so important that levels be identifiable by their severity no. I think I'm pretty satisfied with the current levels API, I think it is a good compromise that is compatible with most use case while also maintaining some consistency. However, I understand that I cannot meet everyone's needs. I wish Loguru was compatible with your concerns, but for the reasons we discussed it does not seem fully possible. One thing for sure, though, is that I will made |
Using a string as a level identifier is actually not as self-explanatory as you say. You can not deduce the levels order by only their names. It is however possible with numerical values, of course as long as you know if the order is ascending or descending. Also I agree that As of for why I am bothered by custom levels having the same height as core ones, it simply is against what the level purpose. The goal of the log level is to filter based on the desired height, so having several levels at the same height have no advantage, logging with a level of And now about why I think the name of core levels should be immutable as well, it is because changing them would break the interface contract of the logger. This would make the shortcuts like I hope this help you understand my point of view, it becomes hard to stay concise :p |
Yes, it helps, thank you for taking the time to write this. However, I do understand "why [you] think the name of core levels should be immutable", I don't understand why you think Fundamentally, I probably agree with what you're saying, but in my opinion it's not worth it considering the drawbacks. |
The biggest advantage I see is that it would make logging and loguru pretty much interchangeable, it would be possible to migrate from one to another transparently, which would be very nice. |
Ok, thanks. It would somehow ease the migration process, but it does not seem very useful in the context of Loguru solely hence I prefer to keep the API as is. |
I made the level |
The behaviors when logging with the level set as "INFO" or 20 is different, though they share the same level number.
I noticed that because I wanted to use logging levels constant:
If the level number is registered in loguru it should be matched and used instead of displaying the generic
"Level %d" % level_no
message without any colorization.It would also be nice to have Loguru providing the level numbers as constant (e.g loguru.INFO), otherwise levels are just magic strings that cannot be easily looked up or referenced.
The text was updated successfully, but these errors were encountered: