-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathlog.lua
More file actions
70 lines (60 loc) · 1.43 KB
/
log.lua
File metadata and controls
70 lines (60 loc) · 1.43 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
local M = {}
local config = require('opencode.config')
local log_path = config.logging and config.logging.outfile or vim.fn.stdpath('log') .. '/opencode.log'
local level = config.logging and config.logging.level or 'warn'
local logger = require('plenary.log').new({
plugin = 'opencode',
level = level:lower(),
use_console = false,
outfile = log_path,
})
local function get_logger()
return logger
end
function M.debug(msg, ...)
if not config.logging.enabled then
return
end
get_logger().debug(string.format(msg, ...))
end
function M.info(msg, ...)
if not config.logging.enabled then
return
end
get_logger().info(string.format(msg, ...))
end
function M.warn(msg, ...)
if not config.logging.enabled then
return
end
get_logger().warn(string.format(msg, ...))
end
function M.error(msg, ...)
if not config.logging.enabled then
return
end
get_logger().error(string.format(msg, ...))
end
--- @return string
function M.get_path()
if not config.logging.enabled then
return
end
return log_path
end
--- Emit a user-visible notification and write the same message to the log.
--- @param msg string
--- @param level integer vim.log.levels.*
function M.notify(msg, level)
if level == vim.log.levels.ERROR then
M.error(msg)
elseif level == vim.log.levels.WARN then
M.warn(msg)
else
M.info(msg)
end
vim.schedule(function()
vim.notify('[opencode.nvim] ' .. msg, level)
end)
end
return M