diff --git a/src/libexpr/paths.cc b/src/libexpr/paths.cc index 7e409738a..87aee2af0 100644 --- a/src/libexpr/paths.cc +++ b/src/libexpr/paths.cc @@ -52,7 +52,7 @@ SourcePath EvalState::decodePath(std::string_view s, PosIdx pos) SourcePath path {accessor->second, CanonPath(s)}; static bool warned = false; - warnOnce(warned, fmt("applying 'toString' to path '%s' and then accessing it is deprecated, at %s", path, positions[pos])); + warnOnce(warned, "applying 'toString' to path '%s' and then accessing it is deprecated, at %s", path, positions[pos]); return path; } catch (std::invalid_argument & e) { diff --git a/src/libutil/logging.cc b/src/libutil/logging.cc index a8ab78546..9702de1ad 100644 --- a/src/libutil/logging.cc +++ b/src/libutil/logging.cc @@ -105,14 +105,6 @@ public: Verbosity verbosity = lvlInfo; -void warnOnce(bool & haveWarned, const FormatOrString & fs) -{ - if (!haveWarned) { - warn(fs.s); - haveWarned = true; - } -} - void writeToStderr(std::string_view s) { try { diff --git a/src/libutil/logging.hh b/src/libutil/logging.hh index ae7a5917b..4642c49f7 100644 --- a/src/libutil/logging.hh +++ b/src/libutil/logging.hh @@ -225,7 +225,11 @@ inline void warn(const std::string & fs, const Args & ... args) logger->warn(f.str()); } -void warnOnce(bool & haveWarned, const FormatOrString & fs); +#define warnOnce(haveWarned, args...) \ + if (!haveWarned) { \ + haveWarned = true; \ + warn(args); \ + } void writeToStderr(std::string_view s);