Skip to content

Commit a65078e

Browse files
authored
#1060 use one log file with the option to truncate (#1075)
1 parent 2457e14 commit a65078e

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ require'nvim-tree'.setup {
191191
},
192192
log = {
193193
enable = false,
194+
truncate = false,
194195
types = {
195196
all = false,
196197
config = false,

doc/nvim-tree-lua.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ function.
164164
},
165165
log = {
166166
enable = false,
167+
truncate = false,
167168
types = {
168169
all = false,
169170
config = false,
@@ -476,6 +477,10 @@ Here is a list of the options available in the setup call:
476477
type: `boolean`
477478
default: `false`
478479

480+
- |log.truncate|: remove existing log file at startup
481+
type: `boolean`
482+
default: `false`
483+
479484
- |log.types|: specify which information to log
480485

481486
- |log.types.all|: everything

lua/nvim-tree.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ local DEFAULT_OPTS = {
395395
},
396396
log = {
397397
enable = false,
398+
truncate = false,
398399
types = {
399400
all = false,
400401
config = false,

lua/nvim-tree/log.lua

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,23 @@ function M.raw(typ, fmt, ...)
1919
io.close(file)
2020
end
2121

22-
-- Write to log file
22+
-- Write to log file via M.raw
2323
-- time and typ are prefixed and a trailing newline is added
2424
function M.line(typ, fmt, ...)
2525
if not M.path or not M.config.types[typ] and not M.config.types.all then
2626
return
2727
end
2828

29-
M.raw(typ, string.format("[%s] [%s] %s\n", os.date "%H:%M:%S", typ, fmt), ...)
29+
M.raw(typ, string.format("[%s] [%s] %s\n", os.date "%Y:%m:%d %H:%M:%S", typ, fmt), ...)
3030
end
3131

3232
function M.setup(opts)
3333
M.config = opts.log
3434
if M.config and M.config.enable and M.config.types then
35-
M.path = string.format("%s/nvim-tree-%s-%s.log", vim.fn.stdpath "cache", os.date "%H:%M:%S", vim.env.USER)
35+
M.path = string.format("%s/nvim-tree.log", vim.fn.stdpath "cache", os.date "%H:%M:%S", vim.env.USER)
36+
if M.config.truncate then
37+
os.remove(M.path)
38+
end
3639
print("nvim-tree.lua logging to " .. M.path)
3740
end
3841
end

0 commit comments

Comments
 (0)