-
Notifications
You must be signed in to change notification settings - Fork 22
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 maxlog
example
#59
Conversation
I found it useful, and am using this code in beacon-biosignals/BeaconK8sUtilities.jl#14
Co-authored-by: Fredrik Ekre <[email protected]>
Co-authored-by: Fredrik Ekre <[email protected]>
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
end is 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