Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 151e4e74cf | |||
| 42b66366ae | |||
| b0761fae75 |
+1
-1
@@ -1,6 +1,6 @@
|
||||
name = "GeneralUtils"
|
||||
uuid = "c6c72f09-b708-4ac8-ac7c-2084d70108fe"
|
||||
version = "0.6.7"
|
||||
version = "0.6.9"
|
||||
authors = ["tonaerospace <tonaerospace.etc@gmail.com>"]
|
||||
|
||||
[deps]
|
||||
|
||||
+17
-20
@@ -4,7 +4,7 @@ export timedifference, showstracktrace, findHighestIndexKey, uuid4snakecase, rep
|
||||
findMatchingDictKey, randstring, randstrings, timeout,
|
||||
dataframeToCSV, dfToVectorDict, disintegrate_vectorDict, getDataFrameValue, dfRowtoString,
|
||||
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,
|
||||
extractTextBetweenCharacter, extractTextBetweenString,
|
||||
convertCamelSnakeKebabCase, fitrange, recentElementsIndex, nonRecentElementsIndex
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user