From 6e56ab4150d3ec0e1fa8b7490303d27c3a2e2662 Mon Sep 17 00:00:00 2001 From: ThePrimeagen Date: Thu, 6 May 2021 13:22:56 -0600 Subject: [PATCH] feat(logging): Enhanced the logging Made a key appear on all the logs so its easy to read each sessions data instead of one big ass-file --- README.md | 25 ++++++++++--------------- lua/harpoon/dev.lua | 22 ++++++++++++++++++++-- lua/harpoon/init.lua | 4 +++- plugin/mark.vim | 2 +- 4 files changed, 34 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 831dd8d..83de38c 100644 --- a/README.md +++ b/README.md @@ -161,22 +161,17 @@ require("harpoon").setup({ } } }, - - -- This uses the wildcard api, you can check it out via branch wildcards - -- not quite ready yet for mainline. - -- Wildcards are to be used in conjunction with git worktrees (at least - -- that is my goal) - ["/home/theprimeagen/personal/harpoon/{}"] = { - term = { - cmds = { - "echo hello {}" - } - }, - }, - ``` ## Debugging -Harpoon writes logs to a `harpoon.log` file that resides in Neovim's cache path. (`:echo stdpath("cache")` to find where that is for you.) +Harpoon writes logs to a `harpoon.log` file that resides in Neovim's cache +path. (`:echo stdpath("cache")` to find where that is for you.) -By default, logging is enabled for warnings and above. This can be changed by setting `vim.g.harpoon_log_level` variable to one of the following log levels: `trace`, `debug`, `info`, `warn`, `error`, or `fatal`. Note that this would have to be done **before** harpoon's `setup` call. Alternatively, it can be more convenient to launch Neovim with an environment variable, e.g. `> HARPOON_LOG=trace nvim`. In case both, `vim.g` and an environment variable are used, the log level set by the environment variable overrules. Supplying an invalid log level defaults back to warnings. +By default, logging is enabled for warnings and above. This can be changed by +setting `vim.g.harpoon_log_level` variable to one of the following log levels: +`trace`, `debug`, `info`, `warn`, `error`, or `fatal`. Note that this would +have to be done **before** harpoon's `setup` call. Alternatively, it can be +more convenient to launch Neovim with an environment variable, e.g. `> +HARPOON_LOG=trace nvim`. In case both, `vim.g` and an environment variable are +used, the log level set by the environment variable overrules. Supplying an +invalid log level defaults back to warnings. diff --git a/lua/harpoon/dev.lua b/lua/harpoon/dev.lua index 65c57fd..863eba6 100644 --- a/lua/harpoon/dev.lua +++ b/lua/harpoon/dev.lua @@ -9,8 +9,8 @@ M.reload = function() require("plenary.reload").reload_module("harpoon") end +local log_levels = { "trace", "debug", "info", "warn", "error", "fatal" } local function set_log_level() - local log_levels = { "trace", "debug", "info", "warn", "error", "fatal" } local log_level = vim.env.HARPOON_LOG or vim.g.harpoon_log_level for _, level in pairs(log_levels) do @@ -22,9 +22,27 @@ local function set_log_level() return "warn" -- default, if user hasn't set to one from log_levels end +local log_level = set_log_level() M.log = require("plenary.log").new({ plugin = "harpoon", - level = set_log_level(), + level = log_level, }) +local log_key = os.time() + +local function override(key) + local fn = M.log[key] + M.log[key] = function(...) + fn(log_key, ...) + end +end + +for _, v in pairs(log_levels) do + override(v) +end + +M.get_log_key = function() + return log_key +end + return M diff --git a/lua/harpoon/init.lua b/lua/harpoon/init.lua index 650ec04..c122a54 100644 --- a/lua/harpoon/init.lua +++ b/lua/harpoon/init.lua @@ -1,6 +1,7 @@ local Path = require("plenary.path") local utils = require("harpoon.utils") -local log = require("harpoon.dev").log +local Dev = require("harpoon.dev") +local log = Dev.log local config_path = vim.fn.stdpath("config") local data_path = vim.fn.stdpath("data") @@ -158,6 +159,7 @@ M.setup = function(config) HarpoonConfig = complete_config log.debug("setup(): Complete config", HarpoonConfig) + log.trace("setup(): log_key", Dev.get_log_key()) end M.get_global_settings = function() diff --git a/plugin/mark.vim b/plugin/mark.vim index 901e445..23b09a5 100644 --- a/plugin/mark.vim +++ b/plugin/mark.vim @@ -1,4 +1,4 @@ augroup THE_PRIMEAGEN_HARPOON autocmd! - autocmd BufLeave * :lua require('harpoon.mark').store_offset() + autocmd BufLeave,VimLeave * :lua require('harpoon.mark').store_offset() augroup END