update
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
name = "GeneralUtils"
|
name = "GeneralUtils"
|
||||||
uuid = "c6c72f09-b708-4ac8-ac7c-2084d70108fe"
|
uuid = "c6c72f09-b708-4ac8-ac7c-2084d70108fe"
|
||||||
version = "0.6.8"
|
version = "0.6.9"
|
||||||
authors = ["tonaerospace <tonaerospace.etc@gmail.com>"]
|
authors = ["tonaerospace <tonaerospace.etc@gmail.com>"]
|
||||||
|
|
||||||
[deps]
|
[deps]
|
||||||
|
|||||||
+16
-19
@@ -1224,27 +1224,8 @@ struct eventSink
|
|||||||
log_file::String
|
log_file::String
|
||||||
max_log_entries::Int
|
max_log_entries::Int
|
||||||
end
|
end
|
||||||
|
|
||||||
eventSink(; natsConn=nothing, topic=nothing, service_name="", log_file="./log/eventSink.md", max_log_entries=100) =
|
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)
|
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)
|
function (es::eventSink)(msg::String; log=false, publish=true, console=true)
|
||||||
timestamp = Dates.format(now(), "yyyy-mm-ddTHH:MM:SS.sss")
|
timestamp = Dates.format(now(), "yyyy-mm-ddTHH:MM:SS.sss")
|
||||||
svc_prefix = isempty(es.service_name) ? "" : "[$(es.service_name)] "
|
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
|
||||||
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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user