From b952fbee8d220691df2e445ea573727ad386769d Mon Sep 17 00:00:00 2001 From: Cameron Nemo Date: Fri, 8 Apr 2022 23:30:59 -0700 Subject: [PATCH] Use XDG_CACHE_HOME for logs --- cli/main.cpp | 23 +++++++++++++---------- doc/kyua.1.in | 15 +++++++++++++-- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/cli/main.cpp b/cli/main.cpp index 531c252b..b0ece49d 100644 --- a/cli/main.cpp +++ b/cli/main.cpp @@ -69,6 +69,7 @@ extern "C" { #include "utils/config/tree.ipp" #include "utils/env.hpp" #include "utils/format/macros.hpp" +#include "utils/fs/exceptions.hpp" #include "utils/fs/operations.hpp" #include "utils/fs/path.hpp" #include "utils/logging/macros.hpp" @@ -239,19 +240,21 @@ fs::path cli::detail::default_log_name(void) { // Update doc/troubleshooting.texi if you change this algorithm. + const optional< std::string > cache(utils::getenv("XDG_CACHE_HOME")); const optional< std::string > home(utils::getenv("HOME")); - if (home) { - return logging::generate_log_name(fs::path(home.get()) / ".kyua" / + const optional< std::string > tmpdir(utils::getenv("TMPDIR")); + if (cache) { + return logging::generate_log_name(fs::path(cache.get()) / "kyua" / "logs", cmdline::progname()); + } else if (home) { + return logging::generate_log_name(fs::path(home.get()) / ".cache" / + "kyua" / "logs", cmdline::progname()); + } else if (tmpdir) { + return logging::generate_log_name(fs::path(tmpdir.get()), + cmdline::progname()); } else { - const optional< std::string > tmpdir(utils::getenv("TMPDIR")); - if (tmpdir) { - return logging::generate_log_name(fs::path(tmpdir.get()), - cmdline::progname()); - } else { - return logging::generate_log_name(fs::path("/tmp"), - cmdline::progname()); - } + return logging::generate_log_name(fs::path("/tmp"), + cmdline::progname()); } } diff --git a/doc/kyua.1.in b/doc/kyua.1.in index 2fca5eb0..4179b44f 100644 --- a/doc/kyua.1.in +++ b/doc/kyua.1.in @@ -210,8 +210,15 @@ If no file is explicitly specified, the location of the log files is chosen in this order: .Bl -enum -offset indent .It -.Pa ${HOME}/.kyua/logs/ +.Pa ${XDG_CACHE_HOME}/kyua/logs/ if +.Va XDG_CACHE_HOME +is defined. +.It +.Pa ${HOME}/.cache/kyua/logs/ +if +.Va XDG_CACHE_HOME +is undefined and .Va HOME is defined. .It @@ -300,7 +307,7 @@ Also, please include a copy of the log file corresponding to the problem you are experiencing. Unless you have changed the location of the log files, you can most likely find them in -.Pa ~/.kyua/logs/ . +.Pa ~/.cache/kyua/logs/ . If the problem is reproducible, it is good idea to regenerate the log file with an increased log level so as to provide more information. For example: @@ -317,6 +324,10 @@ The width of the screen, in number of characters. uses this to wrap long lines. If not present, the width of the screen is determined from the terminal stdout is connected to, and, if the guessing fails, this defaults to infinity. +.It Va XDG_CACHE_HOME +Path to the user's cache directory. +.Nm +uses this location to determine paths to default log files. .It Va HOME Path to the user's home directory. .Nm