-
Notifications
You must be signed in to change notification settings - Fork 8
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
Printing additional information #23
Comments
If you want to use it right now with TerminalLoggers.jl, you can use the sticky message: julia> @info "hello" sticky=true _id=:message_id
julia> @info "another message" sticky=true _id=:message_id
julia> @info "" sticky=:done _id=:message_id # remove I think Juno supports I think a better (although a bit more involved) approach is to create yet another "log record standard" package like ProgressLogging.jl for transient UI messages. Like ProgressLogging.jl, it needs to provide an exception-safe API to cleanup the transient messages when exiting a scope. |
Actually julia> global_logger(SimpleLogger(stderr, Logging.Debug))
julia> @withprogress for i=1:5
if i == 50
@info "Middle of computation" i
elseif i == 70
println("Normal output does not interfere with progress bars")
end
sleep(0.01)
@logprogress "Name $i" i/5 i
end
┌ LogLevel(-1):
│ progress = NaN
└ @ Main /home/chris/.julia/dev/ProgressLogging/src/ProgressLogging.jl:385
┌ LogLevel(-1): Name 1
│ progress = 0.2
│ i = 1
└ @ Main /home/chris/.julia/dev/ProgressLogging/src/ProgressLogging.jl:385
┌ LogLevel(-1): Name 2
│ progress = 0.4
│ i = 2
└ @ Main /home/chris/.julia/dev/ProgressLogging/src/ProgressLogging.jl:385 |
With the current version of the code you can certainly use a separate sticky message if you like. I think it's a bit of a hack though if you intend the message to be "mainly about progress with a bit of other info included". |
Oh by the way, I should point out that with the |
@c42f Juno special-cases
Do you want to support all key-value pairs, like Also, what should happen with a temporary message like this? @withprogress begin
@logprogress 0.1
sleep(0.1)
@logprogress 0.2 message = "message as of 20%"
sleep(0.1)
@logprogress 0.3
sleep(0.1)
end Should |
Hmm, it seems weirdly backward to have the normal log message become the name of the progress bar and then to add a separate I'd be more inclined to have a But I guess that's what I get for encouraging unstructured key-value pairs and not providing any standard or much guidance for these things :-) |
Another thought: the following markdown version would be cute if it worked (but it might also be a bad idea :-) ) @logprogress 0.1 """# $(i)/100
fooing: at element $i""" |
Yeah, I think I agree. This makes writing custom
Yeah, I think that makes sense. I was thinking @pfitzseb What do you think? |
On further consideration I think this would be a reasonable way of doing it: what we want is message text with enough structure to infer a display-specific presentation format and markdown provides that. It also matches conceptually with a more heavy weight type-based approach: struct SummaryAndMessage
summary::String
message::String
end
# ...
@logprogress 0.1 SummaryAndMessage("$(i)/100", "fooing: at element $i""") For context for those who haven't been following the markdown stuff we've introduced in TerminalLoggers, see JuliaLogging/TerminalLoggers.jl#16 |
I'm not particularly attached to the current naming convention. The markdown based approach is neat, but maybe a little too cute. How would we handle arbitrary elements? First |
Yes I was worried about that, but I think there's some benefits beyond being cute. Generally I think we should be preferring log record structure which is logger backend-independent as much as possible. From this point of view putting the "message parts" into what
I'd maybe go even simpler. Something like if if the first markdown content element |
This is the reason why I implemented custom julia> with_logger(SimpleLogger()) do
@info ProgressLogging.Progress(uuid4(), 0.1)
end
┌ Info: Progress: 10%
└ @ Main REPL[9]:2 So, I think another possible solution is to put |
Yes I agree. Though thinking about composition, "message and summary" is a distinct concept from Progress, so I'd be somewhat inclined to throw a "thing which is the message and summary" in as the Progress message (currently the "name" field). (I'm starting to see some kind of pattern here in the logical distinction between the message field as a type vs the key value pairs. Something like... you want to wrap message semantics up in the type for dispatch purposes in the backends, whereas the key value pairs are a way to supply flexible metadata which can be mutated by the log routing pipeline. cf CliMA/ClimateMachine.jl#134 (comment)) |
I think I half agree. On one hand, obviously it's good to make things composable. But on the other hand I want to make Also, I think there is another way to conceptualize this. There can be another messaging UI extension to the logging API (just like ProgressLogging.jl) that handles transient messages. Maybe an API like this: with_transient_message() do msg
msg[] = "Starting..."
@progress for i in 1:10
if i % 3 == 0
msg[] = "It's $i now." # old message is overwritten
end
sleep(0.2)
end
end # clear out `msg` from the UI Implementation: using ProgressLogging
using UUIDs
struct TransientMessage
id::UUID
end
TransientMessage() = TransientMessage(uuid4())
Base.setindex!(msg::TransientMessage, ::Nothing) =
@info "" _id=msg.id sticky=:done
Base.setindex!(msg::TransientMessage, value) =
@info value _id=msg.id sticky=true
function with_transient_message(f)
msg = TransientMessage()
try
f(msg)
finally
msg[] = nothing
end
end A bit crazier thing to do is to allow "nested scoping" of
It has been hard for me to decide when to use which in some kind of principled way. I think what you just said is a good guideline. It makes sense for the routing pipeline to use it as there are no other places to put metadata. From the same line of thought, it makes sense to recommend to try put to everything in the message object if you are creating the log record (as it's only you who can do it). (Though to be honest I still feel a bit uncomfortable that there is only a single namespace to put things. Maybe that's good enough and achieves a good balance, though.) |
Agreed, this makes me uncomfortable too. The frontend interface makes it so simple to attach context in terms of local variables and I still think this is a good thing. But then local variable names can happen to clash with a convention used in the backend for controlling log records, which really seems not-ok :-/ |
This also sounds completely reasonable. I wonder — is there some natural frontend syntax which allows us to be flexible with the representation in the backend? |
With ProgressMeter, it is possible to print additional information. As far as I can see (please correct me if I'm wrong), in principle the old progress logging syntax would allow to provide additional keyword arguments to
@logmsg
or@logprogress
but this is not possible anymore withProgress
and currently there exists no visualization backend for ProgressLogging that would print this additional information.I'm wondering if this would be a useful feature that could be added to ProgressLogging and appropriate visualization backends (such as, e.g., TerminalLoggers), or if there exist alternative approaches that could be used to provide a user with more detailed information without flooding the terminal with
@info
.The text was updated successfully, but these errors were encountered: