aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/nvim/.config/nvim/lua/tobyvin/utils/log.lua
blob: d9ea285f5fae6a744a9e384dba85c9afbfddbeaa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
local log = {}

local status_ok, Log = pcall(require, "plenary.log")
if status_ok then
	log = Log.new({ plugin = "notify" })
end

local levels = {}

for k, v in pairs(vim.log.levels) do
	levels[v] = k:lower()
	levels[k] = k:lower()
	levels[k:lower()] = k:lower()
end

setmetatable(log, {
	__call = function(t, m, l, o)
		local msg = m
		if o and o.title then
			msg = string.format("%s: %s", o.title, msg)
		end

		local level = vim.F.if_nil(levels[l], "info")
		pcall(t[level], msg)

		vim.api.nvim_exec_autocmds("User", {
			pattern = "Notify",
			data = { m, l, o },
		})
	end,
})

vim.notify = log