logger.nvim
提供了一个基础的日志框架,不同的插件可以共用一个日志系统。
安装
和安装其他插件一样,可以使用nvim-plug安装:
require('plug').add({
'wsdjeg/logger.nvim',
config = function()
require('logger').setup({
-- the level only can be:
-- 0 : log debug, info, warn, error messages
-- 1 : log info, warn, error messages
-- 2 : log warn, error messages
-- 3 : log error messages
level = 0,
})
end,
})
在插件中使用
比如新建了一个插件 fyz.nvim
,此时可以添加一个文件 lua/fyz/log.lua
:
local M = {}
local logger
function M.info(msg)
if not logger then
pcall(function()
logger = require('logger').derive('fyz')
logger.info('hello world')
end)
else
logger.info('hello world')
end
end
return M
在自己的插件中就可以使用:
local log = require('fyz.log')
log.info('this is log from fyz.nvim')
可以使用 logger.viewRuntimeLog()
查看所有的日志输出,其中就会有如下一行:
[ fyz ] [23:22:50:576] [ Info ] this is log from fyz.nvim