Skip to content

Commit

Permalink
feat(logging): warn on large log file
Browse files Browse the repository at this point in the history
  • Loading branch information
rcarriga committed Sep 13, 2022
1 parent 775e425 commit c6359d7
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lua/neotest/logging.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ local log_date_format = "%FT%H:%M:%SZ%z"
---@field error function
local Logger = {}

local LARGE = 1e9

---@return neotest.Logger
function Logger.new(filename, opts)
opts = opts or {}
Expand Down Expand Up @@ -47,6 +49,17 @@ function Logger.new(filename, opts)

vim.fn.mkdir(logpath, "p")
local logfile = assert(io.open(logger._filename, "a+"))

local log_info = vim.loop.fs_stat(logger._filename)
if log_info and log_info.size > LARGE then
local warn_msg = string.format(
"Neotest log is large (%d MB): %s",
log_info.size / (1000 * 1000),
logger._filename
)
vim.notify(warn_msg, vim.log.levels.WARN)
end

for level, levelnr in pairs(vim.log.levels) do
logger[level:lower()] = function(...)
local argc = select("#", ...)
Expand Down

0 comments on commit c6359d7

Please sign in to comment.