preview.nvim/lua/render/log.lua
2026-03-01 17:22:59 -05:00

35 lines
666 B
Lua

local M = {}
local enabled = false
local log_file = nil
---@param val boolean|string
function M.set_enabled(val)
if type(val) == 'string' then
enabled = true
log_file = val
else
enabled = val
log_file = nil
end
end
---@param msg string
---@param ... any
function M.dbg(msg, ...)
if not enabled then
return
end
local formatted = '[render.nvim]: ' .. string.format(msg, ...)
if log_file then
local f = io.open(log_file, 'a')
if f then
f:write(string.format('%.6fs', vim.uv.hrtime() / 1e9) .. ' ' .. formatted .. '\n')
f:close()
end
else
vim.notify(formatted, vim.log.levels.DEBUG)
end
end
return M