Add maxlog example - #59
Conversation
I found it useful, and am using this code in beacon-biosignals/BeaconK8sUtilities.jl#14
Co-authored-by: Fredrik Ekre <ekrefredrik@gmail.com>
Co-authored-by: Fredrik Ekre <ekrefredrik@gmail.com>
|
Ah, the way Base does this is it keeps a dictionary of counts of remaining times to emit the log, instead of count of logs emitted. Then in However, I don't really know how to do that in the LoggingExtras framework. It seems we'd need to share state between an EarlyFilteredLogger and a TransformerLogger, or something like that. edit: ah, but that can probably just be done with a closure! |
|
I think function make_maxlog_logger(logger)
counts_remaining = Dict{Any,Int}()
A = ActiveFilteredLogger(logger) do log
maxlog = get(log.kwargs, :maxlog, nothing)
if maxlog isa Integer
remaining = get!(counts_remaining, log.id, Int(maxlog)::Int)
counts_remaining[log.id] = remaining-1
return remaining > 0
else
return true
end
end
return EarlyFilteredLogger(A) do log
return get(counts_remaining, log.id, 1) > 0
end
endis basically what Base is doing. Should I update the example? I'm not totally sure how much of a difference it makes; we can early exit from |
|
That definitely isn't as clean as the example we merged, which is a shame. |
|
Maybe both options can be added to https://julialogging.github.io/ in a "how to throttle messages" section or something like that, and then the complicated example can be included too. |
I found it useful, and am using this code in https://github.com/beacon-biosignals/BeaconK8sUtilities.jl/pull/14