1
- local M = {
2
- config = nil ,
3
- path = nil ,
4
- }
1
+ --- @alias LogTypes " all" | " config" | " copy_paste" | " dev" | " diagnostics" | " git" | " profile" | " watcher"
2
+
3
+ --- @type table<LogTypes , boolean>
4
+ local types = {}
5
+
6
+ --- @type string
7
+ local file_path
8
+
9
+ local M = {}
5
10
6
11
--- Write to log file
7
12
--- @param typ string as per log.types config
@@ -13,7 +18,7 @@ function M.raw(typ, fmt, ...)
13
18
end
14
19
15
20
local line = string.format (fmt , ... )
16
- local file = io.open (M . path , " a" )
21
+ local file = io.open (file_path , " a" )
17
22
if file then
18
23
io.output (file )
19
24
io.write (line )
@@ -22,7 +27,7 @@ function M.raw(typ, fmt, ...)
22
27
end
23
28
24
29
--- Write to a new file
25
- --- @param typ string as per log.types config
30
+ --- @param typ LogTypes as per log.types config
26
31
--- @param path string absolute path
27
32
--- @param fmt string for string.format
28
33
--- @param ... any arguments for string.format
71
76
72
77
--- Write to log file
73
78
--- time and typ are prefixed and a trailing newline is added
74
- --- @param typ string as per log.types config
79
+ --- @param typ LogTypes as per log.types config
75
80
--- @param fmt string for string.format
76
81
--- @param ... any arguments for string.format
77
82
function M .line (typ , fmt , ...)
@@ -88,7 +93,7 @@ function M.set_inspect_opts(opts)
88
93
end
89
94
90
95
--- Write to log file the inspection of a node
91
- --- @param typ string as per log.types config
96
+ --- @param typ LogTypes as per log.types config
92
97
--- @param node Node node to be inspected
93
98
--- @param fmt string for string.format
94
99
--- @param ... any arguments for string.format
@@ -99,20 +104,20 @@ function M.node(typ, node, fmt, ...)
99
104
end
100
105
101
106
--- Logging is enabled for typ or all
102
- --- @param typ string as per log.types config
107
+ --- @param typ LogTypes as per log.types config
103
108
--- @return boolean
104
109
function M .enabled (typ )
105
- return M . path ~= nil and (M . config . types [typ ] or M . config . types .all )
110
+ return file_path ~= nil and (types [typ ] or types .all )
106
111
end
107
112
108
113
function M .setup (opts )
109
- M . config = opts .log
110
- if M . config and M . config . enable and M . config .types then
111
- M . path = string.format (" %s/nvim-tree.log" , vim .fn .stdpath (" log" ), os.date (" %H:%M:%S" ), vim .env .USER )
112
- if M . config .truncate then
113
- os.remove (M . path )
114
+ if opts . log and opts .log . enable and opts . log . types then
115
+ types = opts . log .types
116
+ file_path = string.format (" %s/nvim-tree.log" , vim .fn .stdpath (" log" ), os.date (" %H:%M:%S" ), vim .env .USER )
117
+ if opts . log .truncate then
118
+ os.remove (file_path )
114
119
end
115
- require (" nvim-tree.notify" ).debug (" nvim-tree.lua logging to " .. M . path )
120
+ require (" nvim-tree.notify" ).debug (" nvim-tree.lua logging to " .. file_path )
116
121
end
117
122
end
118
123
0 commit comments