Skip to content

Commit

Permalink
chore: add timestamp to debug messages
Browse files Browse the repository at this point in the history
  • Loading branch information
lewis6991 committed Jun 7, 2024
1 parent 54b9df4 commit 4a143f1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lua/gitsigns/debug/log.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local start_time = vim.loop.hrtime()

local M = {
debug_mode = false,
verbose = false,
Expand Down Expand Up @@ -75,10 +77,11 @@ local function cprint(obj, lvl)
local msg = type(obj) == 'string' and obj or vim.inspect(obj)
local ctx = get_context(lvl)
local msg2 --- @type string
local time = (vim.loop.hrtime() - start_time) / 1e6
if ctx.bufnr then
msg2 = string.format('%s(%s): %s', ctx.name, ctx.bufnr, msg)
msg2 = string.format('[%.3f] %s(%s): %s', time, ctx.name, ctx.bufnr, msg)
else
msg2 = string.format('%s: %s', ctx.name, msg)
msg2 = string.format('[%.3f] %s: %s', time, ctx.name, msg)
end
table.insert(M.messages, msg2)
end
Expand Down Expand Up @@ -116,7 +119,7 @@ local function eprint(msg, level)
if info then
msg = string.format('(ERROR) %s(%d): %s', info.short_src, info.currentline, msg)
end
M.messages[#M.messages + 1] = debug.traceback(msg)
table.insert(M.messages, debug.traceback(msg))
if M.debug_mode then
error(msg, 3)
end
Expand Down
3 changes: 3 additions & 0 deletions test/gs_helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ end
function M.match_lines(lines, spec)
local i = 1
for _, line in ipairs(lines) do
-- Remove leading timestamp
line = line:gsub('^%[[0-9.]+%] ', '')

local s = spec[i]
if line ~= '' and s and match_spec_elem(line, s) then
i = i + 1
Expand Down

0 comments on commit 4a143f1

Please sign in to comment.