#1060 use one log file with the option to truncate (#1075)

This commit is contained in:
Alexander Courtis
2022-03-13 00:43:33 +11:00
committed by GitHub
parent 2457e141ae
commit a65078e3ae
4 changed files with 13 additions and 3 deletions

View File

@@ -19,20 +19,23 @@ function M.raw(typ, fmt, ...)
io.close(file)
end
-- Write to log file
-- Write to log file via M.raw
-- 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), ...)
M.raw(typ, string.format("[%s] [%s] %s\n", os.date "%Y:%m:%d %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)
M.path = string.format("%s/nvim-tree.log", vim.fn.stdpath "cache", os.date "%H:%M:%S", vim.env.USER)
if M.config.truncate then
os.remove(M.path)
end
print("nvim-tree.lua logging to " .. M.path)
end
end