Skip to content

Commit

Permalink
fix: check if log directory exists before writing logs (#17)
Browse files Browse the repository at this point in the history
Previously, if we found the user's workspace, we would just assume that
the `.trunk/logs` directory exists. This PR adds a check for the
directory. If it does not exist, we write logs to a temp file instead.

Fixes #16.
  • Loading branch information
puzzler7 authored Jan 16, 2024
1 parent 1a14c42 commit 4465bd6
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lua/log.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ local function findWorkspace()
return vim.fs.dirname(vim.fs.find({ ".trunk", ".git" }, { upward = true })[1])
end

local function getOutFile()
local log_dir = findWorkspace() and findWorkspace() .. "/.trunk/logs"
if log_dir and vim.fn.isdirectory(log_dir) ~= 0 then
return log_dir .. "/neovim.log"
else
return os.tmpname()
end
end

-- User configuration section
local default_config = {
-- Name of the plugin. Prepended to log messages
Expand All @@ -40,7 +49,7 @@ local default_config = {
use_file = true,

-- Default file to write
out_file = findWorkspace() and findWorkspace() .. "/.trunk/logs/neovim.log" or os.tmpname(),
out_file = getOutFile(),

-- Any messages above this level will be logged.
level = "info",
Expand Down

0 comments on commit 4465bd6

Please sign in to comment.