-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Some logging printing improvements #25111
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -483,23 +483,30 @@ function handle_message(logger::SimpleLogger, level, message, _module, group, id | |
logger.message_limits[id] = remaining - 1 | ||
remaining > 0 || return | ||
end | ||
levelstr = string(level) | ||
color = level < Info ? :blue : | ||
level < Warn ? :cyan : | ||
level < Error ? :yellow : :red | ||
levelstr, color = level < Info ? ("Debug", Base.debug_color()) : | ||
level < Warn ? ("Info", Base.info_color()) : | ||
level < Error ? ("Warning", Base.warn_color()) : | ||
("Error", Base.error_color()) | ||
buf = IOBuffer() | ||
iob = IOContext(buf, logger.stream) | ||
print_with_color(color, iob, first(levelstr), "- ", bold=true) | ||
msglines = split(string(message), '\n') | ||
for i in 1:length(msglines)-1 | ||
println(iob, msglines[i]) | ||
print_with_color(color, iob, "| ", bold=true) | ||
end | ||
println(iob, msglines[end], " -", levelstr, ":", _module, ":", basename(filepath), ":", line) | ||
for (key,val) in pairs(kwargs) | ||
print_with_color(color, iob, "| ", bold=true) | ||
println(iob, key, " = ", val) | ||
msglines = split(chomp(string(message)), '\n') | ||
if length(msglines) + length(kwargs) == 1 | ||
print_with_color(color, iob, "[ ", levelstr, ": ", bold=true) | ||
print(iob, msglines[1], " ") | ||
else | ||
print_with_color(color, iob, "┌ ", levelstr, ": ", bold=true) | ||
println(iob, msglines[1]) | ||
for i in 2:length(msglines) | ||
print_with_color(color, iob, "│ ", bold=true) | ||
println(iob, msglines[i]) | ||
end | ||
for (key,val) in pairs(kwargs) | ||
print_with_color(color, iob, "│ ", bold=true) | ||
println(iob, " ", key, " = ", val) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In particular - if you want exceptions to be readable, it's the printing of |
||
end | ||
print_with_color(color, iob, "└ ", bold=true) | ||
end | ||
print_with_color(:light_black, iob, "@ ", _module, " ", basename(filepath), ":", line, "\n") | ||
write(logger.stream, take!(buf)) | ||
nothing | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing this could end up a bit misleading for custom log levels.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@c42f would you be OK with renaming
Warn
toWarning
? The reason for this change is that all the other levels are nouns, and I prefer we printWarning
overWarn
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's
Warn
vsWarning
which is the sticking point here. The upside of the current naming is thatWarn
is consistent with@warn
, and all the standard levels are four or five characters long.So it seems impossible to have complete consistency without renaming to
@warning
in which case I'd rather just leave it as it currently is. Of course, we can just special case the printing more or less as you've done, but taking into account custom levels. I agree it's not entirely satisfying.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Warning
seems very standarded to use, looking at random pictures of logging on google... Forcing thelevelstr
to be the same as the macro used seems a bit inflexible imo. Why can't we use@warn
and print it asWarning
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Certainly, we can print it differently for logging output, absolutely no problem with that. I thought the issue was about the named constant
Logging.Warn::LogLevel
.For achieving "Warning" printed in the output we can have
string(Logging.Warn) == "Warning"
- seems too inconsistent to really consider.Logging.Warn
->Logging.Warning
(which I thought was being suggested above). I'm not so keen on that, for the reasons of consistency with the spelling of@warn
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps I was confused about what @fredrikekre was suggesting. Sorry if I was misunderstanding.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No probs, I really wish we could get together in the same room to discuss where this stuff is going. It's super slow and easy to get confused / talk at cross purposes in text.
Option (2) is a reasonable way out if you want to try it @fredrikekre and see how it feels? I'm not really sure where the best compromise of (2) vs (3) lies. They both have some inconsistencies, unfortunately.