Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use XDG_CACHE_HOME for logs #217

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 13 additions & 10 deletions cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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());
}
}

Expand Down
15 changes: 13 additions & 2 deletions doc/kyua.1.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is potentially misleading after this change, as the location isn't clearcut if $XDG_CACHE_HOME is not set.

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:
Expand All @@ -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
Copy link
Contributor

@ngie-eign ngie-eign May 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's possibly duplicate/misleading text under the $HOME description below after this change.

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
Expand Down