From 405423108fc31981c40116a827e845a1179c9053 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Mon, 9 Aug 2021 19:02:37 +0200 Subject: feat: Add an async logger using plenary (#1207) Co-authored-by: rebuilt --- lua/core/log.lua | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 lua/core/log.lua (limited to 'lua/core/log.lua') diff --git a/lua/core/log.lua b/lua/core/log.lua new file mode 100644 index 00000000..5dd5622e --- /dev/null +++ b/lua/core/log.lua @@ -0,0 +1,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 = lvim.log.level } +end + +return Log -- cgit v1.2.3