File logging (#1053)
* add file logging infrastructure * log git runner operations * log configuration and mappings * document file logging infrastructure * style fixes * stylua fixes * document log file locations
This commit is contained in:
committed by
GitHub
parent
0816064a8b
commit
19075f41e8
40
lua/nvim-tree/log.lua
Normal file
40
lua/nvim-tree/log.lua
Normal file
@@ -0,0 +1,40 @@
|
||||
local M = {
|
||||
config = nil,
|
||||
path = nil,
|
||||
}
|
||||
|
||||
--- Write to log file
|
||||
--- @param typ as per log.types config
|
||||
--- @param fmt for string.format
|
||||
--- @param ... arguments for string.format
|
||||
function M.raw(typ, fmt, ...)
|
||||
if not M.path or not M.config.types[typ] and not M.config.types.all then
|
||||
return
|
||||
end
|
||||
|
||||
local line = string.format(fmt, ...)
|
||||
local file = io.open(M.path, "a")
|
||||
io.output(file)
|
||||
io.write(line)
|
||||
io.close(file)
|
||||
end
|
||||
|
||||
-- Write to log file
|
||||
-- time and typ are prefixed and a trailing newline is added
|
||||
function M.line(typ, fmt, ...)
|
||||
if not M.path or not M.config.types[typ] and not M.config.types.all then
|
||||
return
|
||||
end
|
||||
|
||||
M.raw(typ, string.format("[%s] [%s] %s\n", os.date "%H:%M:%S", typ, fmt), ...)
|
||||
end
|
||||
|
||||
function M.setup(opts)
|
||||
M.config = opts.log
|
||||
if M.config and M.config.enable and M.config.types then
|
||||
M.path = string.format("%s/nvim-tree-%s-%s.log", vim.fn.stdpath "cache", os.date "%H:%M:%S", vim.env.USER)
|
||||
print("nvim-tree.lua logging to " .. M.path)
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
Reference in New Issue
Block a user