-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathlog.lua
More file actions
54 lines (45 loc) · 1.04 KB
/
log.lua
File metadata and controls
54 lines (45 loc) · 1.04 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
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
return M