diff options
Diffstat (limited to 'lua/core')
| -rw-r--r-- | lua/core/log.lua | 43 | ||||
| -rw-r--r-- | lua/core/lualine/styles.lua | 5 | ||||
| -rw-r--r-- | lua/core/nvimtree.lua | 2 | ||||
| -rw-r--r-- | lua/core/terminal.lua | 4 | 
4 files changed, 42 insertions, 12 deletions
| diff --git a/lua/core/log.lua b/lua/core/log.lua index 5dd5622e..54620625 100644 --- a/lua/core/log.lua +++ b/lua/core/log.lua @@ -4,26 +4,57 @@ local Log = {}  ---@param opts these are passed verbatim to Plenary.log  ---@return log handle  function Log:new(opts) -  local status_ok, _ = pcall(require, "plenary.log") +  local status_ok, handle = pcall(require, "plenary.log")    if not status_ok then -    return nil +    vim.notify("Plenary.log is not available. Logging to console only", vim.log.levels.DEBUG)    end -  local obj = require("plenary.log").new(opts) +  self.__handle = handle +    local path = string.format("%s/%s.log", vim.api.nvim_call_function("stdpath", { "cache" }), opts.plugin) -  obj.get_path = function() +  self.get_path = function()      return path    end -  return obj +  setmetatable({}, Log) +  return self +end + +function Log:add_entry(msg, level) +  local status_ok, _ = pcall(require, "plenary.log") +  if not status_ok then +    return vim.notify(msg, vim.log.levels[level]) +  end +  -- plenary uses lower-case log levels +  return self.__handle[level:lower()](msg)  end  --- Creates or retrieves a log handle for the default logfile  --- based on Plenary.log  ---@return log handle -function Log:get_default() +function Log:new_default()    return Log:new { plugin = "lunarvim", level = lvim.log.level }  end +function Log:trace(msg) +  self:add_entry(msg, "TRACE") +end + +function Log:debug(msg) +  self:add_entry(msg, "DEBUG") +end + +function Log:info(msg) +  self:add_entry(msg, "INFO") +end + +function Log:warn(msg) +  self:add_entry(msg, "TRACE") +end + +function Log:error(msg) +  self:add_entry(msg, "TRACE") +end +  return Log diff --git a/lua/core/lualine/styles.lua b/lua/core/lualine/styles.lua index 876d7fa3..53b0691e 100644 --- a/lua/core/lualine/styles.lua +++ b/lua/core/lualine/styles.lua @@ -112,14 +112,13 @@ function M.get_style(style)    local style_keys = vim.tbl_keys(styles)    if not vim.tbl_contains(style_keys, style) then      local Log = require "core.log" -    local logger = Log:get_default() -    logger.error( +    Log:error(        "Invalid lualine style",        string.format('"%s"', style),        "options are: ",        string.format('"%s"', table.concat(style_keys, '", "'))      ) -    logger.info '"lvim" style is applied.' +    Log:info '"lvim" style is applied.'      style = "lvim"    end diff --git a/lua/core/nvimtree.lua b/lua/core/nvimtree.lua index bea1add4..b5a6cc8d 100644 --- a/lua/core/nvimtree.lua +++ b/lua/core/nvimtree.lua @@ -52,7 +52,7 @@ end  function M.setup()    local status_ok, nvim_tree_config = pcall(require, "nvim-tree.config")    if not status_ok then -    Log:get_default().error "Failed to load nvim-tree.config" +    Log:error "Failed to load nvim-tree.config"      return    end    local g = vim.g diff --git a/lua/core/terminal.lua b/lua/core/terminal.lua index 4fced26e..f9be8734 100644 --- a/lua/core/terminal.lua +++ b/lua/core/terminal.lua @@ -82,7 +82,7 @@ M._exec_toggle = function(exec)    local binary = M._split(exec)[1]    if vim.fn.executable(binary) ~= 1 then      local Log = require "core.log" -    Log:get_default().error("Unable to run executable " .. binary .. ". Please make sure it is installed properly.") +    Log:error("Unable to run executable " .. binary .. ". Please make sure it is installed properly.")      return    end    local Terminal = require("toggleterm.terminal").Terminal @@ -122,7 +122,7 @@ M.toggle_log_view = function(name)    local Terminal = require("toggleterm.terminal").Terminal    local log_view = Terminal:new(term_opts) -  -- require("core.log"):get_default().debug("term", vim.inspect(term_opts)) +  -- require("core.log"):debug("term", vim.inspect(term_opts))    log_view:toggle()  end | 
