log.lua 703 B

1234567891011121314151617181920212223242526272829
  1. local Log = {}
  2. --- Creates a log handle based on Plenary.log
  3. ---@param opts these are passed verbatim to Plenary.log
  4. ---@return log handle
  5. function Log:new(opts)
  6. local status_ok, _ = pcall(require, "plenary.log")
  7. if not status_ok then
  8. return nil
  9. end
  10. local obj = require("plenary.log").new(opts)
  11. local path = string.format("%s/%s.log", vim.api.nvim_call_function("stdpath", { "cache" }), opts.plugin)
  12. obj.get_path = function()
  13. return path
  14. end
  15. return obj
  16. end
  17. --- Creates or retrieves a log handle for the default logfile
  18. --- based on Plenary.log
  19. ---@return log handle
  20. function Log:get_default()
  21. return Log:new { plugin = "lunarvim", level = lvim.log.level }
  22. end
  23. return Log