Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ require'nvim-tree'.setup {
},
log = {
enable = false,
truncate = false,
types = {
all = false,
config = false,
Expand Down
5 changes: 5 additions & 0 deletions doc/nvim-tree-lua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ function.
},
log = {
enable = false,
truncate = false,
types = {
all = false,
config = false,
Expand Down Expand Up @@ -476,6 +477,10 @@ Here is a list of the options available in the setup call:
type: `boolean`
default: `false`

- |log.truncate|: remove existing log file at startup
type: `boolean`
default: `false`

- |log.types|: specify which information to log

- |log.types.all|: everything
Expand Down
1 change: 1 addition & 0 deletions lua/nvim-tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ local DEFAULT_OPTS = {
},
log = {
enable = false,
truncate = false,
types = {
all = false,
config = false,
Expand Down
9 changes: 6 additions & 3 deletions lua/nvim-tree/log.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down