Skip to content
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

Implement the standard logging levels with same logic as custom log levels #52696

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

oxinabox
Copy link
Contributor

@oxinabox oxinabox commented Jan 2, 2024

Follow up to
#52359

Not entirely convinced this is a good idea, but wanted to put it out there for comment.
A big reason why i don't know that it is a good idea is that we can't actually use the custom log level macro as it is in the logging stdlib rather than in Base.CoreLogging.
I thus reimplement the code it would generate, though i could instead move it into Base.CoreLogging which would probably be cleaner.

I do think it is a good feature to have the color be optional and to default to the ones defined by the nearest of error/warn/debug/info.
Since those are user configurable colors.
Which honestly kinda seem like the right colors anyway.
A user defined trace should use same color as debug, and a user defined critical should use the same color as either warn or error depending on which it is closer to.
Not some made up color that might not match how user has configured their system.

Comment on lines 60 to +70
function default_logcolor(level::LogLevel)
level in keys(custom_log_levels) ? custom_log_levels[level][2] :
level < Info ? Base.debug_color() :
level < Warn ? Base.info_color() :
level < Error ? Base.warn_color() :
Base.error_color()
color = get(_log_levels, level, nothing)
if isnothing(color)
# default colors: based such that colors for standard log levels (Info etc) are in middle of color range
level = level.level
color = level < -500 ? Base.debug_color() :
level < 500 ? Base.info_color() :
level < 1500 ? Base.warn_color() :
Base.error_color()
end
return color
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic is here, which I am unsure about.
It could instead be inside the code for @create_log_macro
to be called at definition time.

Pros of in putting it in @create_log_macro:

  • is that the color wouldn't be Logger specific, so user configured loggers could take advantage of it.

Cons of in putting it in @create_log_macro:

  • We would need some trick to make it actually continue to read the enviroment variable behimds debug_color etc at runtime (rather than at compile time). I am not sure what that trick would be.
  • Wouldn't have a definition for what color to use if the log level was defined via the constructor only, rather than the macro. Which people do do right now. Could have the logic in both, or simpler logic that just says use color 1 if we do not have a color defined for that level.

@oxinabox
Copy link
Contributor Author

oxinabox commented Jan 2, 2024

@IanButterworth thoughts?

@quinnj @nickrobinson251 this would make the original design of e.g. @infov verbosity=2 as LogLevel(Info - 2) in LoggingExtras color correctly. (though also defining it using the new @create_log_level macro could do that, just would require hard coding color)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant