@@ -80,9 +80,8 @@ local log_maker = {}
8080
8181--- @class (partial ) neotree.Logger.PartialConfig : neotree.Logger.Config
8282--- @param config neotree.Logger.PartialConfig | neotree.Logger.Config
83- --- @param parent neotree.Logger ?
8483--- @return neotree.Logger
85- log_maker .new = function (config , parent )
84+ log_maker .new = function (config )
8685 --- @class neotree.Logger
8786 local log = {}
8887 --- @diagnostic disable-next-line : cast-local-type
@@ -187,7 +186,7 @@ log_maker.new = function(config, parent)
187186 --- @param log_level vim.log.levels
188187 --- @param message_maker fun ( ... ): string
189188 local logfunc = function (log_level , message_maker )
190- if log_level > log .minimum_level .file and log_level > log .minimum_level .console then
189+ if log_level < log .minimum_level .file and log_level < log .minimum_level .console then
191190 return function () end
192191 end
193192 local level_config = config .level_configs [log_level ]
@@ -220,15 +219,17 @@ log_maker.new = function(config, parent)
220219 --- @param lvl neotree.Log.Level
221220 --- @return vim.log.levels
222221 local to_loglevel = function (lvl )
222+ if type (lvl ) == " number" then
223+ return lvl
224+ end
225+
223226 if type (lvl ) == " string" then
224227 local levelupper = lvl :upper ()
225228 for name , level_num in pairs (Levels ) do
226229 if levelupper == name then
227230 return level_num
228231 end
229232 end
230- elseif type (lvl ) == " number" then
231- return lvl
232233 end
233234 notify (" Couldn't resolve log level " .. lvl .. " defaulting to log level INFO" , Levels .WARN )
234235 return Levels .INFO
@@ -287,33 +288,37 @@ log_maker.new = function(config, parent)
287288 --- @return boolean using_file
288289 log .use_file = function (file , quiet )
289290 if file == false then
291+ config .use_file = false
290292 if not quiet then
291293 log .info (" Logging to file disabled" )
292294 end
295+ return config .use_file
296+ end
297+ log .outfile = type (file ) == " string" and file or initial_filepath
298+ local fp , err = io.open (log .outfile , " a+" )
299+
300+ if not fp then
293301 config .use_file = false
294- else
295- if type (file ) == " string" then
296- log .outfile = file
297- else
298- log .outfile = initial_filepath
299- end
300- local fp = io.open (log .outfile , " a+" )
301- if fp then
302- local new_logfile_ino = assert (uv .fs_stat (log .outfile )).ino
303- if new_logfile_ino ~= current_logfile_inode then
304- -- the fp is pointing to a new/different file than previously
305- log .file = fp
306- log .file :setvbuf (" line" )
307- current_logfile_inode = new_logfile_ino
308- end
309- config .use_file = true
310- if not quiet then
311- log .info (" Logging to file:" , log .outfile )
312- end
313- else
314- config .use_file = false
315- log .warn (" Could not open log file:" , log .outfile )
316- end
302+ log .warn (" Could not open log file:" , log .outfile , err )
303+ return config .use_file
304+ end
305+
306+ local stat , stat_err = uv .fs_stat (log .outfile )
307+ if not stat then
308+ config .use_file = false
309+ log .warn (" Could not stat log file:" , log .outfile , stat_err )
310+ return config .use_file
311+ end
312+
313+ if stat .ino ~= current_logfile_inode then
314+ -- the fp is pointing to a different file
315+ log .file = fp
316+ log .file :setvbuf (" line" )
317+ current_logfile_inode = stat .ino
318+ end
319+ config .use_file = true
320+ if not quiet then
321+ log .info (" Logging to file:" , log .outfile )
317322 end
318323 return config .use_file
319324 end
@@ -353,8 +358,7 @@ log_maker.new = function(config, parent)
353358 " force" ,
354359 config ,
355360 { context = vim .list_extend ({ new_context }, { context }) }
356- ),
357- log
361+ )
358362 )
359363 end
360364
0 commit comments