Skip to content

Commit

Permalink
libruleset: update timestamp format
Browse files Browse the repository at this point in the history
Signed-off-by: He Xian <[email protected]>
  • Loading branch information
hexian000 committed Nov 10, 2024
1 parent 7c12f0e commit f45d19b
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions libruleset.lua
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,20 @@ local function evlog_(now, msg)
recent_events:push({
msg = msg,
count = 1,
tstamp = now
tstamp = now,
})
end

local function format_timestamp(t)
local s = os.date("%Y-%m-%dT%T%z", t)
return s:sub(1, -3) .. ":" .. s:sub(-2, -1)
end

local function log_(now, info, msg)
if config.loglevel < 6 then
return
end
local timestamp = os.date("%Y-%m-%dT%T%z", now)
local timestamp = format_timestamp(now)
local source = info.source:match("^@.-([^/]+)$") or info.short_src
local line = info.currentline
return printf("D %s %s:%d %s", timestamp, source, line, msg)
Expand Down Expand Up @@ -946,7 +951,7 @@ function ruleset.stats(dt)
for i = 1, 10 do
local entry = recent_events:get(i)
if not entry then break end
local tstamp = os.date("%Y-%m-%dT%T%z", entry.tstamp)
local tstamp = format_timestamp(entry.tstamp)
if entry.count == 1 then
w:insertf("%s %s", tstamp, entry.msg)
else
Expand Down

0 comments on commit f45d19b

Please sign in to comment.