From 03ab20e191a3743a7186a9e0453fe2e86df53a78 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Sun, 24 Aug 2025 20:28:43 +0200 Subject: [PATCH] libutil, cli: remove Logger::warn only use the free function instead, so we can turn that into a macro. Change-Id: I0319e9f7bdebb96f6159053e8b7b7a82559c9b33 --- lix/libutil/logging.cc | 5 ----- lix/libutil/logging.hh | 8 ++++---- lix/nix/flake.cc | 15 ++++++++++++--- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/lix/libutil/logging.cc b/lix/libutil/logging.cc index c301b1706..3e3ed3548 100644 --- a/lix/libutil/logging.cc +++ b/lix/libutil/logging.cc @@ -21,11 +21,6 @@ static GlobalConfig::Register rLoggerSettings(&loggerSettings); Logger * logger = makeSimpleLogger(true); -void Logger::warn(const std::string & msg) -{ - log(lvlWarn, ANSI_WARNING "warning:" ANSI_NORMAL " " + msg); -} - void Logger::writeToStdout(std::string_view s) { writeFull( diff --git a/lix/libutil/logging.hh b/lix/libutil/logging.hh index 8e9aaf662..4ebccb02d 100644 --- a/lix/libutil/logging.hh +++ b/lix/libutil/logging.hh @@ -140,8 +140,6 @@ public: logEI(ei); } - virtual void warn(const std::string & msg); - virtual void startActivity(ActivityId act, Verbosity lvl, ActivityType type, const std::string & s, const Fields & fields, ActivityId parent) { }; @@ -279,9 +277,11 @@ extern Verbosity verbosity; * if verbosity >= lvlWarn, print a message with a yellow 'warning:' prefix. */ template -inline void warn(const std::string & fs, const Args & ... args) +inline void warn(const std::string & fs, const Args &... args) { - logger->warn(HintFmt(fs, args...).str()); + logger->log( + lvlWarn, fmt(ANSI_WARNING "warning:" ANSI_NORMAL " %1%", HintFmt(fs, args...).str()) + ); } void writeLogsToStderr(std::string_view s); diff --git a/lix/nix/flake.cc b/lix/nix/flake.cc index 2051f2c1a..ee638c141 100644 --- a/lix/nix/flake.cc +++ b/lix/nix/flake.cc @@ -1340,7 +1340,10 @@ struct CmdFlakeShow : FlakeCommand, MixJSON if (!json) logger->cout(fmt("%s " ANSI_WARNING "omitted" ANSI_NORMAL " (use '--all-systems' to show)", headerPrefix)); else { - logger->warn(fmt("%s omitted (use '--all-systems' to show)", concatStringsSep(".", attrPath))); + warn( + "%s omitted (use '--all-systems' to show)", + concatStringsSep(".", attrPath) + ); } } else { if (visitor.isDerivation(*state)) @@ -1364,13 +1367,19 @@ struct CmdFlakeShow : FlakeCommand, MixJSON if (!json) logger->cout(fmt("%s " ANSI_WARNING "omitted" ANSI_NORMAL " (use '--legacy' to show)", headerPrefix)); else { - logger->warn(fmt("%s omitted (use '--legacy' to show)", concatStringsSep(".", attrPath))); + warn( + "%s omitted (use '--legacy' to show)", + concatStringsSep(".", attrPath) + ); } } else if (!showAllSystems && attrPath[1] != localSystem) { if (!json) logger->cout(fmt("%s " ANSI_WARNING "omitted" ANSI_NORMAL " (use '--all-systems' to show)", headerPrefix)); else { - logger->warn(fmt("%s omitted (use '--all-systems' to show)", concatStringsSep(".", attrPath))); + warn( + "%s omitted (use '--all-systems' to show)", + concatStringsSep(".", attrPath) + ); } } else { if (visitor.isDerivation(*state))