@@ -58,7 +58,7 @@ log.new = function(config, standalone)
58
58
string.format (" %s/%s.log" , vim .api .nvim_call_function (" stdpath" , { " data" }), config .plugin )
59
59
60
60
local obj
61
- if standalone then
61
+ if not standalone then
62
62
obj = log
63
63
else
64
64
obj = {}
@@ -68,7 +68,7 @@ log.new = function(config, standalone)
68
68
obj .use_file = function (file , quiet )
69
69
if file == false then
70
70
if not quiet then
71
- obj .info (" [neo-tree] Logging to file disabled" )
71
+ obj .info (" Logging to file disabled" )
72
72
end
73
73
config .use_file = false
74
74
else
@@ -79,7 +79,7 @@ log.new = function(config, standalone)
79
79
end
80
80
config .use_file = true
81
81
if not quiet then
82
- obj .info (" [neo-tree] Logging to file: " .. obj .outfile )
82
+ obj .info (" Logging to file: " .. obj .outfile )
83
83
end
84
84
end
85
85
end
@@ -126,6 +126,21 @@ log.new = function(config, standalone)
126
126
return table.concat (t , " " )
127
127
end
128
128
129
+ --- @param name string
130
+ --- @param msg string
131
+ local log_to_file = function (name , msg )
132
+ local info = debug.getinfo (2 , " Sl" )
133
+ local lineinfo = info .short_src .. " :" .. info .currentline
134
+ local str = string.format (" [%-6s%s] %s: %s\n " , name , os.date (), lineinfo , msg )
135
+ local fp = io.open (obj .outfile , " a" )
136
+ if fp then
137
+ fp :write (str )
138
+ fp :close ()
139
+ else
140
+ print (" [neo-tree] Could not open log file: " .. obj .outfile )
141
+ end
142
+ end
143
+
129
144
local log_at_level = function (level , level_config , message_maker , ...)
130
145
-- Return early if we're below the config.level
131
146
if level < levels [config .level ] then
@@ -135,22 +150,13 @@ log.new = function(config, standalone)
135
150
if vim .v .dying > 0 or vim .v .exiting ~= vim .NIL then
136
151
return
137
152
end
138
- local nameupper = level_config .name :upper ()
139
153
140
154
local msg = message_maker (... )
141
- local info = debug.getinfo (2 , " Sl" )
142
- local lineinfo = info .short_src .. " :" .. info .currentline
143
155
144
156
-- Output to log file
145
157
if config .use_file then
146
- local str = string.format (" [%-6s%s] %s: %s\n " , nameupper , os.date (), lineinfo , msg )
147
- local fp = io.open (obj .outfile , " a" )
148
- if fp then
149
- fp :write (str )
150
- fp :close ()
151
- else
152
- print (" [neo-tree] Could not open log file: " .. obj .outfile )
153
- end
158
+ local nameupper = level_config .name :upper ()
159
+ log_to_file (nameupper , msg )
154
160
end
155
161
156
162
-- Output to console
@@ -178,16 +184,19 @@ log.new = function(config, standalone)
178
184
end )
179
185
end
180
186
end
187
+
181
188
obj .assert = function (v , ...)
182
- vim .print (v )
183
189
if v then
184
190
return v , ...
185
191
end
186
- obj .error (... )
192
+ if config .use_file then
193
+ log_to_file (" ERROR" , table.concat ({ ... }, " " ))
194
+ end
195
+ error (... )
187
196
end
188
197
end
189
198
190
- log .new (default_config , true )
199
+ log .new (default_config , false )
191
200
-- }}}
192
201
193
202
return log
0 commit comments