feat(log): add easy way to open log
This commit is contained in:
parent
385b951938
commit
5ea71be825
4 changed files with 31 additions and 23 deletions
|
|
@ -3,6 +3,23 @@
|
||||||
-- for the code i have stolen(or have inspected by idk)
|
-- for the code i have stolen(or have inspected by idk)
|
||||||
local c = require "gopher.config"
|
local c = require "gopher.config"
|
||||||
|
|
||||||
|
---@class Gopher.Logger
|
||||||
|
---@field get_outfile fun():string
|
||||||
|
---@field trace fun(...)
|
||||||
|
---@field fmt_trace fun(...)
|
||||||
|
---@field debug fun(...)
|
||||||
|
---@field fmt_debug fun(...)
|
||||||
|
---@field info fun(...)
|
||||||
|
---@field fmt_info fun(...)
|
||||||
|
---@field warn fun(...)
|
||||||
|
---@field fmt_warn fun(...)
|
||||||
|
---@field error fun(...)
|
||||||
|
---@field fmt_error fun(...)
|
||||||
|
|
||||||
|
---@type Gopher.Logger
|
||||||
|
---@diagnostic disable-next-line: missing-fields
|
||||||
|
local log = {}
|
||||||
|
|
||||||
local config = {
|
local config = {
|
||||||
-- Name of the plugin. Prepended to log messages
|
-- Name of the plugin. Prepended to log messages
|
||||||
name = c.___plugin_name,
|
name = c.___plugin_name,
|
||||||
|
|
@ -32,28 +49,12 @@ local config = {
|
||||||
-- Can limit the number of decimals displayed for floats
|
-- Can limit the number of decimals displayed for floats
|
||||||
float_precision = 0.01,
|
float_precision = 0.01,
|
||||||
}
|
}
|
||||||
|
function log.get_outfile()
|
||||||
---@class Gopher.Logger
|
return table.concat {
|
||||||
---@field outfile string
|
|
||||||
---@field trace fun(...)
|
|
||||||
---@field fmt_trace fun(...)
|
|
||||||
---@field debug fun(...)
|
|
||||||
---@field fmt_debug fun(...)
|
|
||||||
---@field info fun(...)
|
|
||||||
---@field fmt_info fun(...)
|
|
||||||
---@field warn fun(...)
|
|
||||||
---@field fmt_warn fun(...)
|
|
||||||
---@field error fun(...)
|
|
||||||
---@field fmt_error fun(...)
|
|
||||||
|
|
||||||
---@type Gopher.Logger
|
|
||||||
---@diagnostic disable-next-line: missing-fields
|
|
||||||
local log = {
|
|
||||||
outfile = table.concat {
|
|
||||||
(vim.fn.has "nvim-0.8.0" == 1) and vim.fn.stdpath "log" or vim.fn.stdpath "cache",
|
(vim.fn.has "nvim-0.8.0" == 1) and vim.fn.stdpath "log" or vim.fn.stdpath "cache",
|
||||||
("/%s.log"):format(config.name),
|
("/%s.log"):format(config.name),
|
||||||
},
|
}
|
||||||
}
|
end
|
||||||
|
|
||||||
-- selene: allow(incorrect_standard_library_use)
|
-- selene: allow(incorrect_standard_library_use)
|
||||||
local unpack = unpack or table.unpack
|
local unpack = unpack or table.unpack
|
||||||
|
|
@ -133,7 +134,7 @@ do
|
||||||
|
|
||||||
-- Output to log file
|
-- Output to log file
|
||||||
if config.use_file then
|
if config.use_file then
|
||||||
local fp = assert(io.open(log.outfile, "a"))
|
local fp = assert(io.open(log.get_outfile(), "a"))
|
||||||
local str = string.format("[%-6s%s] %s: %s\n", nameupper, os.date(), lineinfo, msg)
|
local str = string.format("[%-6s%s] %s: %s\n", nameupper, os.date(), lineinfo, msg)
|
||||||
fp:write(str)
|
fp:write(str)
|
||||||
fp:close()
|
fp:close()
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ local _config = default_config
|
||||||
-- if you don't belive me that i am secret see
|
-- if you don't belive me that i am secret see
|
||||||
-- the line below it says @private
|
-- the line below it says @private
|
||||||
---@private
|
---@private
|
||||||
_config.___plugin_name = "gopher.nvim"
|
_config.___plugin_name = "gopher.nvim" ---@diagnostic disable-line: inject-field
|
||||||
|
|
||||||
---@param user_config? gopher.Config
|
---@param user_config? gopher.Config
|
||||||
function config.setup(user_config)
|
function config.setup(user_config)
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
---@tag gopher.nvim-table-of-contents
|
---@tag gopher.nvim-table-of-contents
|
||||||
---@toc
|
---@toc
|
||||||
|
|
||||||
|
local log = require "gopher._utils.log"
|
||||||
local tags = require "gopher.struct_tags"
|
local tags = require "gopher.struct_tags"
|
||||||
local tests = require "gopher.gotests"
|
local tests = require "gopher.gotests"
|
||||||
local gocmd = require("gopher._utils.runner.gocmd").run
|
local gocmd = require("gopher._utils.runner.gocmd").run
|
||||||
|
|
@ -21,7 +22,12 @@ local gopher = {}
|
||||||
--- Calling this function is optional, if you ok with default settings. Look |gopher.nvim.config-defaults|
|
--- Calling this function is optional, if you ok with default settings. Look |gopher.nvim.config-defaults|
|
||||||
---
|
---
|
||||||
---@usage `require("gopher").setup {}` (replace `{}` with your `config` table)
|
---@usage `require("gopher").setup {}` (replace `{}` with your `config` table)
|
||||||
gopher.setup = require("gopher.config").setup
|
gopher.setup = function(user_config)
|
||||||
|
log.debug "setting up config"
|
||||||
|
log.debug(vim.inspect(user_config))
|
||||||
|
|
||||||
|
require("gopher.config").setup(user_config)
|
||||||
|
end
|
||||||
|
|
||||||
---@toc_entry Install dependencies
|
---@toc_entry Install dependencies
|
||||||
---@tag gopher.nvim-install-deps
|
---@tag gopher.nvim-install-deps
|
||||||
|
|
|
||||||
|
|
@ -11,3 +11,4 @@ command! -nargs=* GoGenerate :lua require"gopher".generate(<f-args>)
|
||||||
command! GoCmt :lua require"gopher".comment()
|
command! GoCmt :lua require"gopher".comment()
|
||||||
command! GoIfErr :lua require"gopher".iferr()
|
command! GoIfErr :lua require"gopher".iferr()
|
||||||
command! GoInstallDeps :lua require"gopher".install_deps()
|
command! GoInstallDeps :lua require"gopher".install_deps()
|
||||||
|
command! GopherLog :lua vim.cmd("tabnew " .. require("gopher._utils.log").get_outfile())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue