Skip to content

Commit

Permalink
io/Logger: remove printf support
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Nov 15, 2023
1 parent 0667aed commit db3b08e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 46 deletions.
17 changes: 0 additions & 17 deletions src/io/Logger.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,6 @@ LoggerDetail::WriteV(std::string_view domain,
(void)nbytes;
}

void
LoggerDetail::Format(unsigned level, std::string_view domain,
const char *fmt, ...) noexcept
{
if (!CheckLevel(level))
return;

char buffer[2048];

va_list ap;
va_start(ap, fmt);
std::string_view s(buffer, vsnprintf(buffer, sizeof(buffer), fmt, ap));
va_end(ap);

WriteV(domain, {&s, 1});
}

void
LoggerDetail::Fmt(unsigned level, std::string_view domain,
fmt::string_view format_str, fmt::format_args args) noexcept
Expand Down
23 changes: 0 additions & 23 deletions src/io/Logger.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

#pragma once

#include "util/Compiler.h"

#include <fmt/core.h>

#include <cstdint>
Expand All @@ -17,7 +15,6 @@
#include <tuple>
#include <utility>

#include <stdio.h>
#include <inttypes.h>

namespace LoggerDetail {
Expand Down Expand Up @@ -158,10 +155,6 @@ LogConcat(unsigned level, std::string_view domain, Params... _params) noexcept
WriteV(domain, params.values);
}

gcc_printf(3, 4)
void
Format(unsigned level, std::string_view domain, const char *fmt, ...) noexcept;

void
Fmt(unsigned level, std::string_view domain,
fmt::string_view format_str, fmt::format_args args) noexcept;
Expand All @@ -188,15 +181,6 @@ LogConcat(unsigned level, D &&domain, Params... params) noexcept
std::forward<Params>(params)...);
}

template<typename D, typename... Params>
void
LogFormat(unsigned level, D &&domain,
const char *fmt, Params... params) noexcept
{
LoggerDetail::Format(level, std::forward<D>(domain),
fmt, std::forward<Params>(params)...);
}

template<typename S, typename... Args>
void
LogFmt(unsigned level, std::string_view domain,
Expand Down Expand Up @@ -225,13 +209,6 @@ public:
std::forward<Params>(params)...);
}

template<typename... Params>
void Format(unsigned level,
const char *fmt, Params... params) const noexcept {
LoggerDetail::Format(level, GetDomain(),
fmt, std::forward<Params>(params)...);
}

template<typename S, typename... Args>
void Fmt(unsigned level, const S &format_str,
Args&&... args) const noexcept {
Expand Down
14 changes: 8 additions & 6 deletions src/spawn/PidfdEvent.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include <linux/wait.h> // for P_PIDFD on glibc < 2.36
#endif

using std::string_view_literals::operator""sv;

/**
* A custom waitid() system call wrapper which, unlike the glibc
* wrapper, supports the "rusage" parameter.
Expand Down Expand Up @@ -103,12 +105,12 @@ PidfdEvent::OnPidfdReady(unsigned) noexcept
const auto stime = ToSteadyClockDuration(rusage.ru_stime);
const auto stime_f = std::chrono::duration_cast<std::chrono::duration<double>>(stime);

logger.Format(6, "stats: %1.3fs elapsed, %1.3fs user, %1.3fs sys, %ld/%ld faults, %ld/%ld switches",
duration_f.count(),
utime_f.count(),
stime_f.count(),
rusage.ru_minflt, rusage.ru_majflt,
rusage.ru_nvcsw, rusage.ru_nivcsw);
logger.Fmt(6, "stats: {:1.3}s elapsed, {:1.3}s user, {:1.3}s sys, {}/{} faults, {}/{} switches"sv,
duration_f.count(),
utime_f.count(),
stime_f.count(),
rusage.ru_minflt, rusage.ru_majflt,
rusage.ru_nvcsw, rusage.ru_nivcsw);

event.Close();

Expand Down

0 comments on commit db3b08e

Please sign in to comment.