logging: move to XDG_CACHE_HOME (#13739)

while there is some controversy, stdpath('cache') looks like  a better fit for logs than stdpath('data'): you can remove logs without preventing nvim to work which fits the XDG_CACHE_HOME definition of `user specific non-essential data files`.
This commit is contained in:
Michael Lingelbach
2021-01-13 14:20:21 -08:00
committed by GitHub
parent 77a6049e07
commit ea8756f85d
7 changed files with 29 additions and 19 deletions

View File

@@ -204,9 +204,8 @@ describe('startup defaults', function()
end)
describe('$NVIM_LOG_FILE', function()
local datasubdir = iswin() and 'nvim-data' or 'nvim'
local xdgdir = 'Xtest-startup-xdg-logpath'
local xdgdatadir = xdgdir..'/'..datasubdir
local xdgcachedir = xdgdir..'/nvim'
after_each(function()
os.remove('Xtest-logpath')
rmdir(xdgdir)
@@ -218,25 +217,25 @@ describe('startup defaults', function()
}})
eq('Xtest-logpath', eval('$NVIM_LOG_FILE'))
end)
it('defaults to stdpath("data")/log if empty', function()
eq(true, mkdir(xdgdir) and mkdir(xdgdatadir))
it('defaults to stdpath("cache")/log if empty', function()
eq(true, mkdir(xdgdir) and mkdir(xdgcachedir))
clear({env={
XDG_DATA_HOME=xdgdir,
XDG_CACHE_HOME=xdgdir,
NVIM_LOG_FILE='', -- Empty is invalid.
}})
eq(xdgdir..'/'..datasubdir..'/log', string.gsub(eval('$NVIM_LOG_FILE'), '\\', '/'))
eq(xdgcachedir..'/log', string.gsub(eval('$NVIM_LOG_FILE'), '\\', '/'))
end)
it('defaults to stdpath("data")/log if invalid', function()
eq(true, mkdir(xdgdir) and mkdir(xdgdatadir))
it('defaults to stdpath("cache")/log if invalid', function()
eq(true, mkdir(xdgdir) and mkdir(xdgcachedir))
clear({env={
XDG_DATA_HOME=xdgdir,
XDG_CACHE_HOME=xdgdir,
NVIM_LOG_FILE='.', -- Any directory is invalid.
}})
eq(xdgdir..'/'..datasubdir..'/log', string.gsub(eval('$NVIM_LOG_FILE'), '\\', '/'))
eq(xdgcachedir..'/log', string.gsub(eval('$NVIM_LOG_FILE'), '\\', '/'))
end)
it('defaults to .nvimlog if stdpath("data") is invalid', function()
it('defaults to .nvimlog if stdpath("cache") is invalid', function()
clear({env={
XDG_DATA_HOME='Xtest-missing-xdg-dir',
XDG_CACHE_HOME='Xtest-missing-xdg-dir',
NVIM_LOG_FILE='.', -- Any directory is invalid.
}})
eq('.nvimlog', eval('$NVIM_LOG_FILE'))