summaryrefslogtreecommitdiffstatshomepage
path: root/runtime/lua/vim/_core/log.lua
blob: f5503e19abae932f3af9b9e98b2af332e8d69305 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
local M = {}

--- Checks that the logfile is accessible.
function M.check_log_file()
  if vim.fn.mode() == 'c' then -- Ex mode
    return
  end

  local wanted = vim.fn.getenv('__NVIM_LOG_FILE_WANT')
  if not wanted or wanted == vim.NIL then
    return
  end

  local actual = vim.fn.getenv('NVIM_LOG_FILE')

  local msg --[[@type string]]
  if not actual or actual == vim.NIL or actual == '' then
    msg = ('log: %q not accessible, logging disabled (stderr)'):format(wanted)
  elseif actual ~= wanted then
    msg = ('log: %q not accessible, logging to: %q'):format(wanted, actual)
  else
    return
  end

  vim.defer_fn(function()
    vim.notify(msg, vim.log.levels.WARN)
  end, 100)
end

return M