summaryrefslogtreecommitdiff
path: root/.config/nvim/lua/core/log.lua
diff options
context:
space:
mode:
authorGustaf Rydholm <gustaf.rydholm@gmail.com>2021-08-10 23:15:04 +0200
committerGustaf Rydholm <gustaf.rydholm@gmail.com>2021-08-10 23:15:04 +0200
commit540268d618627079c9b958a955b586e1888b46a8 (patch)
tree1a22a5feb457135178b9d4fe8b6c1755f5ca66bc /.config/nvim/lua/core/log.lua
parente79bd3273f58ba38e8fcd716090b89326791afbb (diff)
Major refactor of nvim
Diffstat (limited to '.config/nvim/lua/core/log.lua')
-rw-r--r--.config/nvim/lua/core/log.lua29
1 files changed, 29 insertions, 0 deletions
diff --git a/.config/nvim/lua/core/log.lua b/.config/nvim/lua/core/log.lua
new file mode 100644
index 0000000..d364ffb
--- /dev/null
+++ b/.config/nvim/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 = "nvim", level = options.log.level }
+end
+
+return Log