aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/doc/starting.txt11
-rw-r--r--src/nvim/log.c14
-rw-r--r--test/functional/options/defaults_spec.lua7
3 files changed, 20 insertions, 12 deletions
diff --git a/runtime/doc/starting.txt b/runtime/doc/starting.txt
index 48b9aad58b..79459e74c3 100644
--- a/runtime/doc/starting.txt
+++ b/runtime/doc/starting.txt
@@ -1316,8 +1316,9 @@ file when reading and include:
==============================================================================
Standard Paths *standard-path*
-Nvim stores configuration and data in standard locations. Plugins are strongly
-encouraged to follow this pattern also. Use |stdpath()| to get the paths.
+Nvim stores configuration, data, and logs in standard locations. Plugins are
+strongly encouraged to follow this pattern also. Use |stdpath()| to get the
+paths.
*base-directories* *xdg*
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.
"~/.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
debugging, plugins and RPC clients. >
:echo $NVIM_LOG_FILE
-Usually the file is ~/.cache/nvim/log unless that path is inaccessible
-or if $NVIM_LOG_FILE was set before |startup|.
+By default, the file is located at stdpath('cache')/log unless that path
+is inaccessible or if $NVIM_LOG_FILE was set before |startup|.
vim:noet:tw=78:ts=8:ft=help:norl:
diff --git a/src/nvim/log.c b/src/nvim/log.c
index a90c95c034..98df2c799a 100644
--- a/src/nvim/log.c
+++ b/src/nvim/log.c
@@ -22,6 +22,7 @@
#include "nvim/os/time.h"
#define LOG_FILE_ENV "NVIM_LOG_FILE"
+#define LOGERR "E5010: "
/// Cached location of the expanded log file path decided by log_path_init().
static char log_file_path[MAXPATHL + 1] = { 0 };
@@ -69,6 +70,19 @@ static bool log_path_init(void)
|| log_file_path[0] == '\0'
|| os_isdir((char_u *)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.
char *defaultpath = stdpaths_user_cache_subpath("log");
size_t len = xstrlcpy(log_file_path, defaultpath, size);
diff --git a/test/functional/options/defaults_spec.lua b/test/functional/options/defaults_spec.lua
index 12a31b592d..eb5e284385 100644
--- a/test/functional/options/defaults_spec.lua
+++ b/test/functional/options/defaults_spec.lua
@@ -233,13 +233,6 @@ describe('startup defaults', function()
}})
eq(xdgcachedir..'/log', string.gsub(eval('$NVIM_LOG_FILE'), '\\', '/'))
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)