From 212fdadce413486fc4a5a5f1e0e09bd0eefd87c3 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Thu, 21 Oct 2021 17:51:22 +0200 Subject: fix: handle vim.notify when missing a log level (#1818) --- lua/lvim/core/log.lua | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lua/lvim/core/log.lua') diff --git a/lua/lvim/core/log.lua b/lua/lvim/core/log.lua index 9ddc641f..688246f4 100644 --- a/lua/lvim/core/log.lua +++ b/lua/lvim/core/log.lua @@ -89,6 +89,10 @@ function Log:init() -- Overwrite vim.notify to use the logger vim.notify = function(msg, vim_log_level, opts) nvim_notify_params = opts or {} + -- vim_log_level can be omitted + if type(vim_log_level) == "string" then + vim_log_level = Log.levels[(vim_log_level):upper() or "INFO"] + end -- https://github.com/neovim/neovim/blob/685cf398130c61c158401b992a1893c2405cd7d2/runtime/lua/vim/lsp/log.lua#L5 logger:log(vim_log_level + 1, msg) end -- cgit v1.2.3 From 10df0b5ffd0fd96b210747e9169dad08c81dca1b Mon Sep 17 00:00:00 2001 From: Matteo Bigoi <1781140+crisidev@users.noreply.github.com> Date: Fri, 22 Oct 2021 20:51:32 +0100 Subject: [Bugfix] ensure the log level is never nil (#1820) --- lua/lvim/core/log.lua | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lua/lvim/core/log.lua') diff --git a/lua/lvim/core/log.lua b/lua/lvim/core/log.lua index 688246f4..502fd19b 100644 --- a/lua/lvim/core/log.lua +++ b/lua/lvim/core/log.lua @@ -90,6 +90,9 @@ function Log:init() vim.notify = function(msg, vim_log_level, opts) nvim_notify_params = opts or {} -- vim_log_level can be omitted + if vim_log_level == nil then + vim_log_level = Log.levels["INFO"] + end if type(vim_log_level) == "string" then vim_log_level = Log.levels[(vim_log_level):upper() or "INFO"] end -- cgit v1.2.3 From a96a44a16a46dae0aee0f5689ccfe644d2a27c0f Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Fri, 22 Oct 2021 23:46:43 +0200 Subject: [fix] fix notify's highlight groups and make it optional (#1827) --- lua/lvim/core/log.lua | 57 +++++++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 24 deletions(-) (limited to 'lua/lvim/core/log.lua') diff --git a/lua/lvim/core/log.lua b/lua/lvim/core/log.lua index 502fd19b..557590e1 100644 --- a/lua/lvim/core/log.lua +++ b/lua/lvim/core/log.lua @@ -1,6 +1,7 @@ local Log = {} local logfile = string.format("%s/%s.log", vim.fn.stdpath "cache", "lvim") +local in_headless = #vim.api.nvim_list_uis() == 0 Log.levels = { TRACE = 1, @@ -33,7 +34,7 @@ function Log:init() nvim_notify_params_injecter(nil, {}) local log_level = Log.levels[(lvim.log.level):upper() or "WARN"] - structlog.configure { + local lvim_log = { lvim = { sinks = { structlog.sinks.Console(log_level, { @@ -49,25 +50,6 @@ function Log:init() { level = structlog.formatters.FormatColorizer.color_level() } ), }), - structlog.sinks.NvimNotify(Log.levels.INFO, { - processors = { - nvim_notify_default_namer, - nvim_notify_params_injecter, - }, - formatter = structlog.formatters.Format( -- - "%s", - { "msg" }, - { blacklist_all = true } - ), - params_map = { - icon = "icon", - keep = "keep", - on_open = "on_open", - on_close = "on_close", - timeout = "timeout", - title = "title", - }, - }), structlog.sinks.File(Log.levels.TRACE, logfile, { processors = { structlog.processors.Namer(), @@ -83,12 +65,39 @@ function Log:init() }, } + if not in_headless and lvim.builtin.notify.active then + table.insert( + lvim_log.lvim.sinks, + structlog.sinks.NvimNotify(Log.levels.INFO, { + processors = { + nvim_notify_default_namer, + nvim_notify_params_injecter, + }, + formatter = structlog.formatters.Format( -- + "%s", + { "msg" }, + { blacklist_all = true } + ), + params_map = { + icon = "icon", + keep = "keep", + on_open = "on_open", + on_close = "on_close", + timeout = "timeout", + title = "title", + }, + }) + ) + end + + structlog.configure(lvim_log) + local logger = structlog.get_logger "lvim" - if lvim.log.override_notify then + if not in_headless and lvim.builtin.notify.active and lvim.log.override_notify then -- Overwrite vim.notify to use the logger vim.notify = function(msg, vim_log_level, opts) - nvim_notify_params = opts or {} + nvim_notify_params = vim.tbl_deep_extend("force", lvim.builtin.notify.opts, opts) -- vim_log_level can be omitted if vim_log_level == nil then vim_log_level = Log.levels["INFO"] @@ -109,7 +118,7 @@ end ---@param level string [same as vim.log.log_levels] function Log:add_entry(level, msg, event) if self.__handle then - self.__handle:log(level, msg, event) + self.__handle:log(level, vim.inspect(msg), event) return end @@ -119,7 +128,7 @@ function Log:add_entry(level, msg, event) end self.__handle = logger - self.__handle:log(level, msg, event) + self.__handle:log(level, vim.inspect(msg), event) end ---Retrieves the path of the logfile -- cgit v1.2.3 From 0ea08c7a1c1de5cb381351230d11513e287c42db Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Sat, 23 Oct 2021 13:11:05 +0200 Subject: fix(log): don't rely on lvim.builtin.notify.active (#1831) --- lua/lvim/core/log.lua | 45 ++++++++++++++++----------------------------- 1 file changed, 16 insertions(+), 29 deletions(-) (limited to 'lua/lvim/core/log.lua') diff --git a/lua/lvim/core/log.lua b/lua/lvim/core/log.lua index 557590e1..9950af28 100644 --- a/lua/lvim/core/log.lua +++ b/lua/lvim/core/log.lua @@ -1,7 +1,6 @@ local Log = {} local logfile = string.format("%s/%s.log", vim.fn.stdpath "cache", "lvim") -local in_headless = #vim.api.nvim_list_uis() == 0 Log.levels = { TRACE = 1, @@ -19,20 +18,20 @@ function Log:init() return nil end - local nvim_notify_params = {} - local nvim_notify_params_injecter = function(_, entry) - for key, value in pairs(nvim_notify_params) do - entry[key] = value - end - return entry - end + local notify_handler = require "lvim.core.notify" - local nvim_notify_default_namer = function(logger, entry) - entry["title"] = logger.name - return entry + ---Check if notify is available + ---@return boolean + local is_notify_available = function() + local in_headless = #vim.api.nvim_list_uis() == 0 + --We can't rely on lvim.builtin.notify.active since this can be used before the config loader + local has_notify_plugin = pcall(require, "notify") + if not in_headless and has_notify_plugin then + return true + end + return false end - nvim_notify_params_injecter(nil, {}) local log_level = Log.levels[(lvim.log.level):upper() or "WARN"] local lvim_log = { lvim = { @@ -65,13 +64,13 @@ function Log:init() }, } - if not in_headless and lvim.builtin.notify.active then + if is_notify_available() then table.insert( lvim_log.lvim.sinks, structlog.sinks.NvimNotify(Log.levels.INFO, { processors = { - nvim_notify_default_namer, - nvim_notify_params_injecter, + notify_handler.default_namer, + notify_handler.params_injecter, }, formatter = structlog.formatters.Format( -- "%s", @@ -94,20 +93,8 @@ function Log:init() local logger = structlog.get_logger "lvim" - if not in_headless and lvim.builtin.notify.active and lvim.log.override_notify then - -- Overwrite vim.notify to use the logger - vim.notify = function(msg, vim_log_level, opts) - nvim_notify_params = vim.tbl_deep_extend("force", lvim.builtin.notify.opts, opts) - -- vim_log_level can be omitted - if vim_log_level == nil then - vim_log_level = Log.levels["INFO"] - end - if type(vim_log_level) == "string" then - vim_log_level = Log.levels[(vim_log_level):upper() or "INFO"] - end - -- https://github.com/neovim/neovim/blob/685cf398130c61c158401b992a1893c2405cd7d2/runtime/lua/vim/lsp/log.lua#L5 - logger:log(vim_log_level + 1, msg) - end + if lvim.log.override_notify then + logger:log(Log.levels.INFO, "Ignoring request to override vim.notify with structlog due to instabilities") end return logger -- cgit v1.2.3