gopher.nvim/lua/gopher/_utils/init.lua
Smirnov Oleksandr fbf6441f3d
feat: add logger (#64)
* refactor(health): keep in mind new way of health check (#63)

* feat(log): add logger module

* refactor(utils): remove unused code

* refactor(log, utils): get plugin name from config

* refactor(logger): add some type annotations

* refactor(utils): log notifications

* feat: LOGGER™

* feat(config): TYPES

* refactor(log): dont give a thing about var that is not even declared

* feat(log): add easy way to open log

* refactor(log): some types

* update types

* docs: regen

* fix(log): make setting log level by config work

* feat(iferr): write error to log file if occur

* feat(gotests): add logger
2024-06-15 12:18:26 +03:00

34 lines
728 B
Lua

local c = require "gopher.config"
local log = require "gopher._utils.log"
local utils = {}
---@param msg string
---@param lvl number
function utils.deferred_notify(msg, lvl)
vim.defer_fn(function()
vim.notify(msg, lvl, {
title = c.___plugin_name,
})
log.debug(msg)
end, 0)
end
---@param msg string
---@param lvl? number
function utils.notify(msg, lvl)
lvl = lvl or vim.log.levels.INFO
vim.notify(msg, lvl, {
title = c.___plugin_name,
})
log.debug(msg)
end
-- safe require
---@param module string module name
function utils.sreq(module)
local ok, m = pcall(require, module)
assert(ok, string.format("gopher.nvim dependency error: %s not installed", module))
return m
end
return utils