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

Log datetime #2191

Open
wants to merge 5 commits 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/LogBackend.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,13 @@ EnableLogTimestamp() noexcept
static const char *
log_date() noexcept
{
static constexpr size_t LOG_DATE_BUF_SIZE = 16;
static char buf[LOG_DATE_BUF_SIZE];
time_t t = time(nullptr);
strftime(buf, LOG_DATE_BUF_SIZE, "%b %d %H:%M : ", localtime(&t));
static constexpr size_t LOG_DATE_STR_LEN = std::char_traits<char>::length("Jan 22 15:43:14");
static constexpr size_t LOG_DATE_BUF_SIZE = LOG_DATE_STR_LEN + std::char_traits<char>::length(".000 : ") + 1;
static thread_local char buf[LOG_DATE_BUF_SIZE];
timespec t;
timespec_get(&t, TIME_UTC);
strftime(buf, LOG_DATE_BUF_SIZE, "%b %d %H:%M:%S : ", localtime(&t.tv_sec));
snprintf(&buf[LOG_DATE_STR_LEN], LOG_DATE_BUF_SIZE - LOG_DATE_STR_LEN, ".%03d : ", int(t.tv_nsec / 1e6));
return buf;
}

Expand Down
1 change: 1 addition & 0 deletions src/LogInit.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ log_init(const ConfigData &config, bool verbose, bool use_stdout)

if (use_stdout) {
out_fd = STDOUT_FILENO;
EnableLogTimestamp();
} else {
const auto *param = config.GetParam(ConfigOption::LOG_FILE);
if (param == nullptr) {
Expand Down
2 changes: 1 addition & 1 deletion src/command/PlayerCommands.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ handle_status(Client &client, [[maybe_unused]] Request args, Response &r)
COMMAND_STATUS_PLAYLIST ": {}\n"
COMMAND_STATUS_PLAYLIST_LENGTH ": {}\n"
COMMAND_STATUS_MIXRAMPDB ": {}\n"
COMMAND_STATUS_STATE ": {}\n",
Copy link
Member

Choose a reason for hiding this comment

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

Which commit introduced this bug? This should be mentioned in the commit message so we know whether a backport is necessary.

COMMAND_STATUS_STATE ": {}\n"
COMMAND_STATUS_LOADED_PLAYLIST ": {}\n",
(unsigned)playlist.GetRepeat(),
(unsigned)playlist.GetRandom(),
Expand Down
Loading