The answer is probably no, but can I somehow add to an info "box" in a loop? I.e. I have:
julia> function test()
@info "Starting loop"
for i ∈ 1:5
println("\tRandom number $i is",rand())
end
end
test (generic function with 2 methods)
julia> test()
[ Info: Starting loop
Random number 1 is0.9431049058632653
Random number 2 is0.6857053427685
Random number 3 is0.5635097298087287
Random number 4 is0.6772063413820648
Random number 5 is0.40036800767161795
But I want it to be printed as
julia> @info "This is \n\ta multi line\n\tinfobox"
┌ Info: This is
│ a multi line
└ infobox
Note how the "bracket" on the left hand side goes over multiple lines, grouping them visually together.
julia> @eval @info $(join(["Starting loop"; ("Random number $(i) is $(rand())" for i in 1:5)...], "\n\t"))
┌ Info: Starting loop
│ Random number 1 is 0.08727815644082126
│ Random number 2 is 0.5143229494820801
│ Random number 3 is 0.2279420608548931
│ Random number 4 is 0.06105790644739839
└ Random number 5 is 0.4146310646135424
actually, don't even need @eval
julia> @info join(["Starting loop"; ("Random number $(i) is $(rand())" for i in 1:5)...], "\n\t")
┌ Info: Starting loop
│ Random number 1 is 0.5010904789610295
│ Random number 2 is 0.6292650737151477
│ Random number 3 is 0.11161364590871192
│ Random number 4 is 0.8046665101173005
└ Random number 5 is 0.04649665030116268
this isn't exactly doing what you ask (add to an existing @info
), but perhaps dynamically building the info string is a possible strategy for your case?
He wants the user to be notified at the beginning of the loop iteration though
whereas that won't notify them till the end
I think you could probably do something though where you println("Starting loop")
, and then delete that output after the loop finishes and then do the @info
Hmm, one thing I'm not a fan of with that style in general is the inability to visually differentiate between a single multi-line @info
and multiple independent @info
lines.
You can (probably) do this already with ProgressLogging.jl?
Last updated: Nov 06 2024 at 04:40 UTC