Compare commits

..

3 Commits

Author SHA1 Message Date
ton 151e4e74cf update 2026-09-01 14:35:57 +07:00
ton 42b66366ae update 2026-09-01 12:21:17 +07:00
ton b0761fae75 update 2026-09-01 12:21:02 +07:00
2 changed files with 18 additions and 21 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
name = "GeneralUtils" name = "GeneralUtils"
uuid = "c6c72f09-b708-4ac8-ac7c-2084d70108fe" uuid = "c6c72f09-b708-4ac8-ac7c-2084d70108fe"
version = "0.6.7" version = "0.6.9"
authors = ["tonaerospace <tonaerospace.etc@gmail.com>"] authors = ["tonaerospace <tonaerospace.etc@gmail.com>"]
[deps] [deps]
+17 -20
View File
@@ -4,7 +4,7 @@ export timedifference, showstracktrace, findHighestIndexKey, uuid4snakecase, rep
findMatchingDictKey, randstring, randstrings, timeout, findMatchingDictKey, randstring, randstrings, timeout,
dataframeToCSV, dfToVectorDict, disintegrate_vectorDict, getDataFrameValue, dfRowtoString, dataframeToCSV, dfToVectorDict, disintegrate_vectorDict, getDataFrameValue, dfRowtoString,
dfToString, dataframe_to_json_list, dictToString, dictToString_noKey, issomething, dfToString, dataframe_to_json_list, dictToString, dictToString_noKey, issomething,
dictToString_numbering, extract_triple_backtick_text, logger, eventSink, dictToString_numbering, extract_triple_backtick_text, eventSink,
countGivenWords, remove_french_accents, removestring, countGivenWords, remove_french_accents, removestring,
extractTextBetweenCharacter, extractTextBetweenString, extractTextBetweenCharacter, extractTextBetweenString,
convertCamelSnakeKebabCase, fitrange, recentElementsIndex, nonRecentElementsIndex convertCamelSnakeKebabCase, fitrange, recentElementsIndex, nonRecentElementsIndex
@@ -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