Skip to content

Commit

Permalink
feat: add an option to configure the logging level
Browse files Browse the repository at this point in the history
  • Loading branch information
vyfor committed Jun 15, 2024
1 parent fc4c8bd commit 273d454
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
2 changes: 2 additions & 0 deletions lua/cord.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ local logger = require 'cord.log'

cord.config = {
usercmds = true,
log_level = nil,
timer = {
interval = 1500,
reset_on_idle = false,
Expand Down Expand Up @@ -309,6 +310,7 @@ function cord.setup(userConfig)
if vim.g.cord_initialized == nil then
local config = vim.tbl_deep_extend('force', cord.config, userConfig or {})
config.timer.interval = math.max(config.timer.interval, 500)
logger.init(config.log_level)

discord = utils.init_discord(ffi)
if not discord then return end
Expand Down
29 changes: 25 additions & 4 deletions lua/cord/log.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,33 @@
local function info(msg) vim.notify('[cord.nvim] ' .. msg, vim.log.levels.INFO) end
local log_level

local function warn(msg) vim.notify('[cord.nvim] ' .. msg, vim.log.levels.WARN) end
local function init(level)
log_level = vim.log.levels[string.upper(level)] or vim.log.levels.OFF

if log_level == vim.log.levels.OFF then log_level = -1 end
end

local function info(msg)
if vim.log.levels.INFO >= log_level then
vim.notify('[cord.nvim] ' .. msg, vim.log.levels.INFO)
end
end

local function warn(msg)
if vim.log.levels.WARN >= log_level then
vim.notify('[cord.nvim] ' .. msg, vim.log.levels.WARN)
end
end

local function error(msg)
vim.notify('[cord.nvim] ' .. msg, vim.log.levels.ERROR)
if vim.log.levels.ERROR >= log_level then
vim.notify('[cord.nvim] ' .. msg, vim.log.levels.ERROR)
end
end

local function debug(msg)
vim.notify('[cord.nvim] ' .. msg, vim.log.levels.DEBUG)
if vim.log.levels.DEBUG >= log_level then
vim.notify('[cord.nvim] ' .. msg, vim.log.levels.DEBUG)
end
end

local function log(status_code)
Expand All @@ -23,6 +43,7 @@ local function log(status_code)
end

return {
init = init,
info = info,
warn = warn,
error = error,
Expand Down

0 comments on commit 273d454

Please sign in to comment.