summaryrefslogtreecommitdiff
path: root/.config/nvim/lua/core/log.lua
blob: 35ba4be682516e3e7bcdb5616957fda1eeba9dc4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
local Log = {}

--- Creates a log handle based on Plenary.log
---@param opts these are passed verbatim to Plenary.log
---@return log handle
function Log:new(opts)
  local status_ok, _ = pcall(require, "plenary.log")
  if not status_ok then
    return nil
  end

  local obj = require("plenary.log").new(opts)
  local path = string.format("%s/%s.log", vim.api.nvim_call_function("stdpath", { "cache" }), opts.plugin)

  obj.get_path = function()
    return path
  end

  return obj
end

--- Creates or retrieves a log handle for the default logfile
--- based on Plenary.log
---@return log handle
function Log:get_default()
  return Log:new { plugin = "lunarvim", level = options.log.level }
end

return Log