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 = {}
510
611--- Write to log file
712--- @param typ string as per log.types config
@@ -13,7 +18,7 @@ function M.raw(typ, fmt, ...)
1318 end
1419
1520 local line = string.format (fmt , ... )
16- local file = io.open (M . path , " a" )
21+ local file = io.open (file_path , " a" )
1722 if file then
1823 io.output (file )
1924 io.write (line )
@@ -22,7 +27,7 @@ function M.raw(typ, fmt, ...)
2227end
2328
2429--- Write to a new file
25- --- @param typ string as per log.types config
30+ --- @param typ LogTypes as per log.types config
2631--- @param path string absolute path
2732--- @param fmt string for string.format
2833--- @param ... any arguments for string.format
7176
7277--- Write to log file
7378--- 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
7580--- @param fmt string for string.format
7681--- @param ... any arguments for string.format
7782function M .line (typ , fmt , ...)
@@ -88,7 +93,7 @@ function M.set_inspect_opts(opts)
8893end
8994
9095--- 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
9297--- @param node Node node to be inspected
9398--- @param fmt string for string.format
9499--- @param ... any arguments for string.format
@@ -99,20 +104,20 @@ function M.node(typ, node, fmt, ...)
99104end
100105
101106--- 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
103108--- @return boolean
104109function 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 )
106111end
107112
108113function 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 )
114119 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 )
116121 end
117122end
118123
0 commit comments