diff --git a/pdns/auth-main.cc b/pdns/auth-main.cc index 42b00b779264..94741ff3f27a 100644 --- a/pdns/auth-main.cc +++ b/pdns/auth-main.cc @@ -1226,8 +1226,8 @@ int main(int argc, char** argv) ::arg().laxParse(argc, argv); // do a lax parse if (::arg().mustDo("version")) { - showProductVersion(); - showBuildConfiguration(); + cout << getProductVersion(); + cout << getBuildConfiguration(); return 0; } @@ -1501,7 +1501,9 @@ int main(int argc, char** argv) DLOG(g_log << Logger::Warning << "Verbose logging in effect" << endl); - showProductVersion(); + for (const string& line : getProductVersionLines()) { + g_log << Logger::Info << line << endl; + } try { mainthread(); diff --git a/pdns/recursordist/rec-main.cc b/pdns/recursordist/rec-main.cc index 7cc45c4308e7..f2262f8b3cd9 100644 --- a/pdns/recursordist/rec-main.cc +++ b/pdns/recursordist/rec-main.cc @@ -3153,8 +3153,8 @@ int main(int argc, char** argv) ::arg().laxParse(argc, argv); // do a lax parse if (::arg().mustDo("version")) { - showProductVersion(); - showBuildConfiguration(); + cout << getProductVersion(); + cout << getBuildConfiguration(); return 0; } if (::arg().mustDo("help")) { @@ -3174,7 +3174,10 @@ int main(int argc, char** argv) } g_log.setLoglevel(s_logUrgency); g_log.toConsole(s_logUrgency); - showProductVersion(); + + for (const string& line : getProductVersionLines()) { + g_log << Logger::Info << line << endl; + } if (!::arg().mustDo("structured-logging")) { g_log << Logger::Error << "Disabling structured logging is not supported anymore" << endl; } diff --git a/pdns/version.cc b/pdns/version.cc index d17ac15f18ee..53c76fd13fc9 100644 --- a/pdns/version.cc +++ b/pdns/version.cc @@ -21,11 +21,14 @@ */ #include "config.h" - -#include "logger.hh" #include "version.hh" +#include "namespaces.hh" + +#ifdef PDNS_MODULES #include "dnsbackend.hh" +#endif +#include #include static ProductType productType; @@ -70,27 +73,40 @@ string productTypeApiType() return "unknown"; } -void showProductVersion() +vector getProductVersionLines() { - g_log << Logger::Warning << productName() << " " << VERSION << " (C) " + vector ret; + std::istringstream istr(getProductVersion()); + for (string line; std::getline(istr, line);) { + ret.emplace_back(line); + } + return ret; +} + +string getProductVersion() +{ + ostringstream ret; + ret << productName() << " " << VERSION << " (C) " "PowerDNS.COM BV" << endl; - g_log << Logger::Warning << "Using " << (sizeof(unsigned long) * 8) << "-bits mode. " + ret << "Using " << (sizeof(unsigned long) * 8) << "-bits mode. " "Built using " << compilerVersion() #ifndef REPRODUCIBLE << " on " __DATE__ " " __TIME__ " by " BUILD_HOST #endif << "." << endl; - g_log << Logger::Warning << "PowerDNS comes with ABSOLUTELY NO WARRANTY. " + ret << "PowerDNS comes with ABSOLUTELY NO WARRANTY. " "This is free software, and you are welcome to redistribute it " "according to the terms of the GPL version 2." << endl; + return ret.str(); } -void showBuildConfiguration() +string getBuildConfiguration() { - g_log << Logger::Warning << "Features: " + ostringstream ret; + ret << "Features: " << #ifdef HAVE_LIBDECAF "decaf " @@ -184,19 +200,20 @@ void showBuildConfiguration() endl; #ifdef PDNS_MODULES // Auth only - g_log << Logger::Warning << "Built-in modules: " << PDNS_MODULES << endl; + ret << "Built-in modules: " << PDNS_MODULES << endl; const auto& modules = BackendMakers().getModules(); - g_log << Logger::Warning << "Loaded modules: " << boost::join(modules, " ") << endl; + ret << "Loaded modules: " << boost::join(modules, " ") << endl; #endif // NOLINTBEGIN(cppcoreguidelines-macro-usage) #ifdef PDNS_CONFIG_ARGS #define double_escape(s) #s #define escape_quotes(s) double_escape(s) // NOLINTEND(cppcoreguidelines-macro-usage) - g_log << Logger::Warning << "Configured with: " << escape_quotes(PDNS_CONFIG_ARGS) << endl; + ret << "Configured with: " << escape_quotes(PDNS_CONFIG_ARGS) << endl; #undef escape_quotes #undef double_escape #endif + return ret.str(); } string fullVersionString() diff --git a/pdns/version.hh b/pdns/version.hh index 9d5ef1966af7..c0b63c0a5d1b 100644 --- a/pdns/version.hh +++ b/pdns/version.hh @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #pragma once -#include +#include "namespaces.hh" enum ProductType { @@ -28,12 +28,13 @@ enum ProductType ProductRecursor }; -std::string compilerVersion(); -void showProductVersion(); -void showBuildConfiguration(); -std::string fullVersionString(); -std::string getPDNSVersion(); -std::string productName(); -std::string productTypeApiType(); +[[nodiscard]] std::string compilerVersion(); +[[nodiscard]] std::vector getProductVersionLines(); +[[nodiscard]] std::string getProductVersion(); +[[nodiscard]] std::string getBuildConfiguration(); +[[nodiscard]] std::string fullVersionString(); +[[nodiscard]] std::string getPDNSVersion(); +[[nodiscard]] std::string productName(); +[[nodiscard]] std::string productTypeApiType(); void versionSetProduct(ProductType productType_); -ProductType versionGetProduct(); +[[nodiscard]] ProductType versionGetProduct();