如果我有一个记录太多的@warn
或@info
,是否有一个包或函数可以用来将警告限制为仅记录"每N次"或类似的东西?
我正在寻找类似于谷歌的c ++日志记录库的功能LOG_EVERY_N(INFO, N)
的东西。 https://github.com/google/glog/blob/195d416e3b1c8dc06980439f6acd3ebd40b6b820/src/glog/logging.h.in#L176
我查看了Memento.jl,Suppressor.jl和Base,但找不到这样的东西。 :)
查看有关处理程序的 Memento 文档。要按时间间隔记录,您可以 执行以下操作:
using Memento
mutable struct MyHandler{F<:Formatter, O<:IO} <: Handler{F, O}
fmt::F
io::O
interval::Int
count::Int
end
c = MyHandler(Memento.DefaultFormatter(), stderr, 10, 0)
function emit(handler::MyHandler{F, O}, rec::Record) where {F<:Formatter, O<:IO}
if (handler.count += 1) % handler.interval == 0
str = Memento.format(handler.fmt, rec)
println(handler.io, str)
flush(handler.io)
end
end