From 8c4e17dbec3f443ec9a8dd04729f9503c1f758ad Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Sat, 13 Jun 2026 21:10:58 +0200 Subject: upgrade to std::format --- server/common/log.hpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'server/common') diff --git a/server/common/log.hpp b/server/common/log.hpp index 52f96c1..505faed 100644 --- a/server/common/log.hpp +++ b/server/common/log.hpp @@ -6,10 +6,11 @@ #pragma once #include -#include #include #include +#include +#include #include #include #include @@ -22,8 +23,10 @@ namespace math::server::log { namespace details { -inline std::thread::id get_tid() { - return std::this_thread::get_id(); +inline std::string get_tid() { + std::ostringstream oss; + oss << std::this_thread::get_id(); + return oss.str(); } inline std::string get_timestamp() { @@ -35,23 +38,27 @@ inline std::string get_timestamp() { } inline void log(const std::string& msg) { - std::clog << get_timestamp() << " | " << get_tid() << " | " << msg << '\n'; + std::clog << std::format("{} | {} | {}\n", get_timestamp(), get_tid(), msg); } } // namespace details template -inline void log(std::string_view fmt, Args&&... args) { - details::log(boost::str((boost::format(fmt.data()) % ... % args))); +inline void log(std::format_string fmt, Args&&... args) { + details::log(std::format(fmt, std::forward(args)...)); } template -inline void error(std::string_view fmt, Args&&... args) { - details::log(boost::str((boost::format(fmt.data()) % ... % args))); +inline void error(std::format_string fmt, Args&&... args) { + details::log(std::format(fmt, std::forward(args)...)); } inline void error(const boost::system::error_code& ec) { - details::log(ec.message()); + log("{}", ec.message()); +} + +inline void error(const std::exception& e) { + log("{}", e.what()); } } // namespace math::server::log -- cgit v1.3