log.c: warn instead of error on failed stdpath('cache') creation

This commit is contained in:
Michael Lingelbach
2021-01-16 16:28:46 -08:00
parent abbfaf286f
commit 640febaca7
2 changed files with 8 additions and 10 deletions

View File

@@ -1339,7 +1339,7 @@ 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* *E5010* LOG FILE *$NVIM_LOG_FILE*
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

View File

@@ -22,7 +22,6 @@
#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 };
@@ -73,15 +72,10 @@ static bool log_path_init(void)
// Make kXDGCacheHome if it does not exist. // Make kXDGCacheHome if it does not exist.
char *cachehome = get_xdg_home(kXDGCacheHome); char *cachehome = get_xdg_home(kXDGCacheHome);
char *failed_dir = NULL; char *failed_dir = NULL;
bool log_dir_failure = false;
if (!os_isdir((char_u *)cachehome)) { if (!os_isdir((char_u *)cachehome)) {
int ret; log_dir_failure = (os_mkdir_recurse(cachehome, 0700, &failed_dir) != 0);
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); 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");
@@ -97,6 +91,11 @@ static bool log_path_init(void)
return false; return false;
} }
os_setenv(LOG_FILE_ENV, log_file_path, true); os_setenv(LOG_FILE_ENV, log_file_path, true);
if (log_dir_failure) {
WLOG("Failed to create directory %s for writing logs: %s",
failed_dir, os_strerror(log_dir_failure));
}
XFREE_CLEAR(failed_dir);
} }
return true; return true;
} }
@@ -337,4 +336,3 @@ static bool v_do_log_to_file(FILE *log_file, int log_level,
return true; return true;
} }