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
This commit is contained in:
ThePrimeagen 2021-05-06 13:22:56 -06:00
parent c2b7ef3d37
commit 6e56ab4150
4 changed files with 34 additions and 19 deletions

View File

@ -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.

View File

@ -9,8 +9,8 @@ M.reload = function()
require("plenary.reload").reload_module("harpoon")
end
local function set_log_level()
local log_levels = { "trace", "debug", "info", "warn", "error", "fatal" }
local function set_log_level()
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

View File

@ -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()

View File

@ -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