Skip to content

Commit 6bb0e09

Browse files
authored
feat: option to output logging to the qflist (#247)
1 parent 8c6cc07 commit 6bb0e09

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

lua/plenary/log.lua

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ local default_config = {
2626
-- Should write to a file
2727
use_file = true,
2828

29+
-- Should write to the quickfix list
30+
use_quickfix = false,
31+
2932
-- Any messages above this level will be logged.
3033
level = p_debug and "debug" or "info",
3134

@@ -137,6 +140,19 @@ log.new = function(config, standalone)
137140
fp:write(str)
138141
fp:close()
139142
end
143+
144+
-- Output to quickfix
145+
if config.use_quickfix then
146+
local formatted_msg = string.format("[%s] %s", nameupper, msg)
147+
local qf_entry = {
148+
-- remove the @ getinfo adds to the file path
149+
filename = info.source:sub(2),
150+
lnum = info.currentline,
151+
col = 1,
152+
text = formatted_msg,
153+
}
154+
vim.fn.setqflist({ qf_entry }, "a")
155+
end
140156
end
141157

142158
for i, x in ipairs(config.modes) do

0 commit comments

Comments
 (0)