mirror of
https://github.com/neovim/neovim.git
synced 2025-10-05 09:26:30 +00:00
logs: make kXDGCacheHome if it doesn't exist (#13758)
This commit is contained in:

committed by
GitHub

parent
0fad952a2b
commit
abbfaf286f
@@ -1316,8 +1316,9 @@ file when reading and include:
|
|||||||
==============================================================================
|
==============================================================================
|
||||||
Standard Paths *standard-path*
|
Standard Paths *standard-path*
|
||||||
|
|
||||||
Nvim stores configuration and data in standard locations. Plugins are strongly
|
Nvim stores configuration, data, and logs in standard locations. Plugins are
|
||||||
encouraged to follow this pattern also. Use |stdpath()| to get the paths.
|
strongly encouraged to follow this pattern also. Use |stdpath()| to get the
|
||||||
|
paths.
|
||||||
|
|
||||||
*base-directories* *xdg*
|
*base-directories* *xdg*
|
||||||
The "base" (root) directories conform to the XDG Base Directory Specification.
|
The "base" (root) directories conform to the XDG Base Directory Specification.
|
||||||
@@ -1338,12 +1339,12 @@ DATA DIRECTORY (DEFAULT) ~
|
|||||||
Note: Throughout the user manual these defaults are used as placeholders, e.g.
|
Note: Throughout the user manual these defaults are used as placeholders, e.g.
|
||||||
"~/.config" is understood to mean "$XDG_CONFIG_HOME or ~/.config".
|
"~/.config" is understood to mean "$XDG_CONFIG_HOME or ~/.config".
|
||||||
|
|
||||||
LOG FILE *$NVIM_LOG_FILE*
|
LOG FILE *$NVIM_LOG_FILE* *E5010*
|
||||||
Besides 'debug' and 'verbose', Nvim keeps a general log file for internal
|
Besides 'debug' and 'verbose', Nvim keeps a general log file for internal
|
||||||
debugging, plugins and RPC clients. >
|
debugging, plugins and RPC clients. >
|
||||||
:echo $NVIM_LOG_FILE
|
:echo $NVIM_LOG_FILE
|
||||||
Usually the file is ~/.cache/nvim/log unless that path is inaccessible
|
By default, the file is located at stdpath('cache')/log unless that path
|
||||||
or if $NVIM_LOG_FILE was set before |startup|.
|
is inaccessible or if $NVIM_LOG_FILE was set before |startup|.
|
||||||
|
|
||||||
|
|
||||||
vim:noet:tw=78:ts=8:ft=help:norl:
|
vim:noet:tw=78:ts=8:ft=help:norl:
|
||||||
|
@@ -22,6 +22,7 @@
|
|||||||
#include "nvim/os/time.h"
|
#include "nvim/os/time.h"
|
||||||
|
|
||||||
#define LOG_FILE_ENV "NVIM_LOG_FILE"
|
#define LOG_FILE_ENV "NVIM_LOG_FILE"
|
||||||
|
#define LOGERR "E5010: "
|
||||||
|
|
||||||
/// Cached location of the expanded log file path decided by log_path_init().
|
/// Cached location of the expanded log file path decided by log_path_init().
|
||||||
static char log_file_path[MAXPATHL + 1] = { 0 };
|
static char log_file_path[MAXPATHL + 1] = { 0 };
|
||||||
@@ -69,6 +70,19 @@ static bool log_path_init(void)
|
|||||||
|| log_file_path[0] == '\0'
|
|| log_file_path[0] == '\0'
|
||||||
|| os_isdir((char_u *)log_file_path)
|
|| os_isdir((char_u *)log_file_path)
|
||||||
|| !log_try_create(log_file_path)) {
|
|| !log_try_create(log_file_path)) {
|
||||||
|
// Make kXDGCacheHome if it does not exist.
|
||||||
|
char *cachehome = get_xdg_home(kXDGCacheHome);
|
||||||
|
char *failed_dir = NULL;
|
||||||
|
if (!os_isdir((char_u *)cachehome)) {
|
||||||
|
int ret;
|
||||||
|
if ((ret = os_mkdir_recurse(cachehome, 0700, &failed_dir)) != 0) {
|
||||||
|
EMSG3(_(LOGERR "Failed to create directory %s "
|
||||||
|
"for writing logs: %s"),
|
||||||
|
failed_dir, os_strerror(ret));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
XFREE_CLEAR(failed_dir);
|
||||||
|
XFREE_CLEAR(cachehome);
|
||||||
// Invalid $NVIM_LOG_FILE or failed to expand; fall back to default.
|
// Invalid $NVIM_LOG_FILE or failed to expand; fall back to default.
|
||||||
char *defaultpath = stdpaths_user_cache_subpath("log");
|
char *defaultpath = stdpaths_user_cache_subpath("log");
|
||||||
size_t len = xstrlcpy(log_file_path, defaultpath, size);
|
size_t len = xstrlcpy(log_file_path, defaultpath, size);
|
||||||
|
@@ -233,13 +233,6 @@ describe('startup defaults', function()
|
|||||||
}})
|
}})
|
||||||
eq(xdgcachedir..'/log', string.gsub(eval('$NVIM_LOG_FILE'), '\\', '/'))
|
eq(xdgcachedir..'/log', string.gsub(eval('$NVIM_LOG_FILE'), '\\', '/'))
|
||||||
end)
|
end)
|
||||||
it('defaults to .nvimlog if stdpath("cache") is invalid', function()
|
|
||||||
clear({env={
|
|
||||||
XDG_CACHE_HOME='Xtest-missing-xdg-dir',
|
|
||||||
NVIM_LOG_FILE='.', -- Any directory is invalid.
|
|
||||||
}})
|
|
||||||
eq('.nvimlog', eval('$NVIM_LOG_FILE'))
|
|
||||||
end)
|
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user