diff --git a/Project.toml b/Project.toml index d91dfe5..f074c5a 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "GeneralUtils" uuid = "c6c72f09-b708-4ac8-ac7c-2084d70108fe" -version = "0.6.8" +version = "0.6.9" authors = ["tonaerospace "] [deps] diff --git a/src/util.jl b/src/util.jl index f7c1c81..b11063e 100644 --- a/src/util.jl +++ b/src/util.jl @@ -1224,27 +1224,8 @@ struct eventSink log_file::String max_log_entries::Int end - eventSink(; natsConn=nothing, topic=nothing, service_name="", log_file="./log/eventSink.md", max_log_entries=100) = eventSink(natsConn, topic, service_name, log_file, max_log_entries) - -""" - rotate!(es::eventSink) -> Nothing - -Rewrite the log file keeping only the last `max_log_entries` entries. -Call after writing when the entry count reaches the limit. -""" -function rotate!(es::eventSink) - content = read(es.log_file, String) - entries = split(content, r"- \[", keepempty=false) - open(es.log_file, "w") do f - write(f, "- [") - for e in entries[2:end] - write(f, "- [", e) - end - end -end - function (es::eventSink)(msg::String; log=false, publish=true, console=true) timestamp = Dates.format(now(), "yyyy-mm-ddTHH:MM:SS.sss") svc_prefix = isempty(es.service_name) ? "" : "[$(es.service_name)] " @@ -1274,6 +1255,22 @@ function (es::eventSink)(msg::String; log=false, publish=true, console=true) end end +""" + rotate!(es::eventSink) -> Nothing + +Rewrite the log file keeping only the last `max_log_entries` entries. +Call after writing when the entry count reaches the limit. +""" +function rotate!(es::eventSink) + content = read(es.log_file, String) + entries = split(content, r"- \[", keepempty=false) + open(es.log_file, "w") do f + write(f, "- [") + for e in entries[2:end] + write(f, "- [", e) + end + end +end