-
-
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
add logging() to redirect info/warn/error() #16213
Conversation
08beb50
to
ba7ad9d
Compare
version 2 is new and improved! can now just specify a particular module / function to mute; so Pkg code doesn't need to be modified to mute it. |
I'm willing to have this for now, although I really think we need a more general system for logging info messages, warnings, and errors and controlling where that output goes. "Squelching" is just logging to /dev/null. |
Kind of a strange name as well, is there precedent for this choice elsewhere? |
version 3 is more general for |
f0461ef
to
4cde358
Compare
version 4 now redirects a few questions:
thanks. |
For your first question, not sure without more information about the error. If it happens when julia is being built, then it's likely that this type doesn't yet exist at the time that I'm tentatively assigning @StefanKarpinski to be in charge of helping bring this to conclusion. |
thanks @timholy . re-ordering now just need to figure out how to capture the output of |
Raise an `ErrorException` with the given message. | ||
|
||
See also `logging`. | ||
""" |
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.
the docstring should be attached to the signature that it corresponds to
2a17ff8
to
9f9396e
Compare
i think this is ready to merge. i tried my best to add tests for are there any comments / suggestions to the API or implementation? |
@StefanKarpinski, are you willing to mentor this one through? |
@JeffBezanson, what do you think about this? |
@Rory-Finnegan do you (or any of your colleagues interested in logging) have any opinions about this implementation or whether getting this version incorporated into base for 0.6 would be good/bad/neutral ? Thanks! |
@tanmaykm also uses Logging.jl a fair bit, and may have a perspective here. |
@tkelman I'm very interested in having nice flexible logging functionality in julia, but I'm mostly neutral regarding this implementation. I don't particularly like this solution and won't use this functionality myself, but I don't have any issue with providing this in base for now. FWIW, I think Memento.jl will cover what I need/expect in terms of logging functionality for now. @noah79 you may find the table on this page useful. |
this PR permits users to redirect |
if isempty(log_to) | ||
return io | ||
else | ||
if length(log_to)==1 && in((nothing,nothing),keys(log_to)) |
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.
why isn't this haskey
?
|
||
Stream output of informational, warning, and/or error messages to `io`, | ||
overriding what was otherwise specified. Optionally, divert stream only for | ||
module `m`, or specifically function `f` within `m`. `kind` can also be |
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.
Instead of "also" I'd say "kind
can be :all
(the default), :info
, :warn
, or :error
."
logging(kind=:error) | ||
@test all(contains.(sprint(Logging.bar), ["INFO: barinfo", "WARNING: barwarn"])) | ||
@test all(contains.(sprint(Logging.pooh), ["INFO: poohinfo", "WARNING: poohwarn"])) | ||
@test all(contains.(sprint(foo), ["INFO: fooinfo", "WARNING: foowarn"])) |
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.
shouldn't these include error once again?
bt = bt[1:eval_ind-1] | ||
end | ||
with_output_color(Base.error_color(), io) do io | ||
showerror(IOContext(io, :limit => true), er, bt) |
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.
The version of this from REPL.jl had been setting :limit => true
, but the old implementation in client.jl wasn't - what outputs are you now limiting that weren't before?
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.
my assumption was that whoever added :limit => true
to REPL.jl
simply forgot to add it to client.jl
as well. according to the IOContext
docstring it simply truncates long containers with ellipses.
as an alternative, we could continue to keep maintaining two versions of display_error
. i was just trying to remove some repetition figuring it'd make maintenance easier.
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.
what used to determine which of the two would get called?
@@ -507,7 +507,7 @@ temp_pkg_dir() do | |||
|
|||
ret, out, err = @grab_outputs Pkg.update("Example") | |||
@test ret === nothing && out == "" | |||
@test contains(err, "INFO: Package Example: skipping update (pinned)...\n") | |||
@test contains(err, "INFO: Package Example: skipping update (pinned)...") |
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.
do you know why these changed?
if eval_ind != 0 | ||
bt = bt[1:eval_ind-1] | ||
end | ||
with_output_color(Base.error_color(), io) do io |
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.
This doesn't look right compared to whats in REPL.jl
.
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.
yet this line remains precisely what used to be in client.jl
; i've left this line unchanged.
IIRC a few months ago the two copies of display_error
(in client.jl
and REPL.jl
) were identical. there has been more than one occasion where someone changed one, but not the other, when i think they should've changed both, and either forgot to or were unaware of the other copy.
please let me know if i am wrong in thinking that the two copies shouldn't behave identically. if this is not the case, then this PR should be modified so as not to delete the one in REPL.jl
.
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.
Previously the REPL.jl
called Base.showerror
. Now it calls this method which does not do the same thing as the one you deleted from REPL.jl
. The result is that errors being printed to the REPL will now be different.
It looks like
Line 1303 in 962583e
display_error(e, catch_backtrace()) |
client.jl
version of display_error
. Updating the client.jl
to match REPL.jl
would be the best way forward in my opinion.
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.
it's a do-block. showerror
is called in the next line.
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.
I know. That do
block is not present in REPL.jl
.
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.
i'm confused. can you be more precise in describing what you want changed?
julia v0.5.0 had no calls to with_output_color
until you added it to both REPL.jl
and client.jl
. at some later point, it was deleted from REPL.jl
but not client.jl
. are you saying i should delete your change from the latter as well?
it still seems to me that if the goal is that the output should be the same, then there should just be a single function, and not two.
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.
julia v0.5.0 had no calls to with_output_color until you added it to both REPL.jl and client.jl
No, that commit simply changed, :red
-> Base.error_color()
. It did not add or remove any do
blocks.
In a later PR the do
block was deleted from REPL.jl
. I am saying you can do the same in client.jl
.
the one test that fails appears to be spurious. is there a way to just re-do it and not all the others? |
Restarted, failing worker. Previous failing log at https://gist.github.com/KristofferC/486937a09a0ef731ac2c2b2a3fb64ee4 |
thanks. how could i have done that myself? |
You'd need member status for the repo. |
I'm inclined to merge this if no one objects in the next day or so. |
As the author of Logging.jl, I'll chime in and say that silencing or redirecting info, warn, and/or error messages seems a reasonable thing to have, although it seems to me this is mostly to remove warts--e.g., to stop reams of deprecation warnings or other verbosity that should really be fixed, but for some reason the user is unable or unwilling to do so. This implementation seems reasonable enough. It's a little verbose to silence or redirect things, and because of this, it probably won't be used much, but it's probably better to at least have this functionality. I agree with the above statements that a fuller (extensible) logging module belongs in base, and that, except for lack of documentation, Memento.jl looks like an interesting implementation. A couple of things I would love to see (but won't have any time to work on soon):
|
@kmsquire I realize that this is a bit off topic, but if you have specific documentation concerns feel free to open an issue. I realize that the README is a bit sparse, but I'd appreciate your feedback on what's missing on the hosted docs. |
Log would read a bit ambiguously with logarithm to me. An implementation big enough to be a package should probably stay that way, but if widely liked and used we could consider it for inclusion as a "default package." Modifications needed to base to better support that kind of logging module can be considered going forward, of course. |
@bjarthur, congrats on your perseverance in getting this merged! Off topic: @Rory-Finnegan, sorry, I missed the link to the full docs at the top of the readme. Many packages Include an explicit pointer to the full docs (if they exist)--maybe you could add such a line? (I'd submit a PR, but I'm mostly off grid with no computer for the next week.) |
@Rory-Finnegan I should have found your Memento.jl earlier so that I didn't have to write MiniLogging.jl for my company. |
this PR provides a mechanism by which info, warning, and error messages can be
organized hierarchically andselectively redirected to an IO stream of your choice.a keyword argument provided to warn identifies it's position within the hierarchy by subclassing a new abstract typea new commandWarning
.logging()
is used to maintain aset of branches within the hierarchymapping between the kind of message, and optionally specific modules and/or functions, to a stream.for example, given this module:
the user could selectively mute
warn()
inpooh()
by