* fix(#1970): additional log function gating for efficiency when not logging * fix(#1970): additional log function gating for efficiency when not logging
This commit is contained in:
committed by
GitHub
parent
59e65d88db
commit
02fdc262eb
@@ -880,8 +880,10 @@ function M.setup(conf)
|
|||||||
require("nvim-tree.notify").setup(opts)
|
require("nvim-tree.notify").setup(opts)
|
||||||
require("nvim-tree.log").setup(opts)
|
require("nvim-tree.log").setup(opts)
|
||||||
|
|
||||||
log.line("config", "default config + user")
|
if log.enabled "config" then
|
||||||
log.raw("config", "%s\n", vim.inspect(opts))
|
log.line("config", "default config + user")
|
||||||
|
log.raw("config", "%s\n", vim.inspect(opts))
|
||||||
|
end
|
||||||
|
|
||||||
require("nvim-tree.actions").setup(opts)
|
require("nvim-tree.actions").setup(opts)
|
||||||
require("nvim-tree.keymap").setup(opts)
|
require("nvim-tree.keymap").setup(opts)
|
||||||
|
|||||||
@@ -437,8 +437,10 @@ function M.setup(opts)
|
|||||||
|
|
||||||
require("nvim-tree.actions.dispatch").setup(M.custom_keypress_funcs)
|
require("nvim-tree.actions.dispatch").setup(M.custom_keypress_funcs)
|
||||||
|
|
||||||
log.line("config", "active mappings")
|
if log.enabled "config" then
|
||||||
log.raw("config", "%s\n", vim.inspect(M.mappings))
|
log.line("config", "active mappings")
|
||||||
|
log.raw("config", "%s\n", vim.inspect(M.mappings))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ function Runner:_getopts(stdout_handle, stderr_handle)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Runner:_log_raw_output(output)
|
function Runner:_log_raw_output(output)
|
||||||
if output and type(output) == "string" then
|
if log.enabled "git" and output and type(output) == "string" then
|
||||||
log.raw("git", "%s", output)
|
log.raw("git", "%s", output)
|
||||||
log.line("git", "done")
|
log.line("git", "done")
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ local M = {
|
|||||||
--- @param fmt string for string.format
|
--- @param fmt string for string.format
|
||||||
--- @vararg any arguments for string.format
|
--- @vararg any arguments for string.format
|
||||||
function M.raw(typ, fmt, ...)
|
function M.raw(typ, fmt, ...)
|
||||||
if not M.path or not M.config.types[typ] and not M.config.types.all then
|
if not M.enabled(typ) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -21,32 +21,48 @@ function M.raw(typ, fmt, ...)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Write to log file via M.line
|
--- Write profile start to log file
|
||||||
--- START is prefixed
|
--- START is prefixed
|
||||||
|
--- @param fmt string for string.format
|
||||||
|
--- @vararg any arguments for string.format
|
||||||
--- @return number nanos to pass to profile_end
|
--- @return number nanos to pass to profile_end
|
||||||
function M.profile_start(fmt, ...)
|
function M.profile_start(fmt, ...)
|
||||||
if not M.path or not M.config.types.profile and not M.config.types.all then
|
if M.enabled "profile" then
|
||||||
|
M.line("profile", "START " .. (fmt or "???"), ...)
|
||||||
|
return vim.loop.hrtime()
|
||||||
|
else
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
M.line("profile", "START " .. (fmt or "???"), ...)
|
|
||||||
return vim.loop.hrtime()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Write to log file via M.line
|
--- Write profile end to log file
|
||||||
--- END is prefixed and duration in seconds is suffixed
|
--- END is prefixed and duration in seconds is suffixed
|
||||||
--- @param start number nanos returned from profile_start
|
--- @param start number nanos returned from profile_start
|
||||||
|
--- @param fmt string for string.format
|
||||||
|
--- @vararg any arguments for string.format
|
||||||
function M.profile_end(start, fmt, ...)
|
function M.profile_end(start, fmt, ...)
|
||||||
if not M.path or not M.config.types.profile and not M.config.types.all then
|
if M.enabled "profile" then
|
||||||
return
|
local millis = start and math.modf((vim.loop.hrtime() - start) / 1000000) or -1
|
||||||
|
M.line("profile", "END " .. (fmt or "???") .. " " .. millis .. "ms", ...)
|
||||||
end
|
end
|
||||||
local millis = start and math.modf((vim.loop.hrtime() - start) / 1000000) or -1
|
|
||||||
M.line("profile", "END " .. (fmt or "???") .. " " .. millis .. "ms", ...)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Write to log file via M.raw
|
--- Write to log file
|
||||||
-- time and typ are prefixed and a trailing newline is added
|
--- time and typ are prefixed and a trailing newline is added
|
||||||
|
--- @param typ string as per log.types config
|
||||||
|
--- @param fmt string for string.format
|
||||||
|
--- @vararg any arguments for string.format
|
||||||
function M.line(typ, fmt, ...)
|
function M.line(typ, fmt, ...)
|
||||||
M.raw(typ, string.format("[%s] [%s] %s\n", os.date "%Y-%m-%d %H:%M:%S", typ, fmt), ...)
|
if M.enabled(typ) then
|
||||||
|
M.raw(typ, string.format("[%s] [%s] %s\n", os.date "%Y-%m-%d %H:%M:%S", typ, fmt), ...)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Logging is enabled for typ or all
|
||||||
|
--- @param typ string as per log.types config
|
||||||
|
--- @return boolean
|
||||||
|
function M.enabled(typ)
|
||||||
|
return M.path ~= nil and (M.config.types[typ] or M.config.types.all)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.setup(opts)
|
function M.setup(opts)
|
||||||
|
|||||||
Reference in New Issue
Block a user