add LOG_FORMAT.

This commit is contained in:
luocai 2024-09-04 12:28:49 +08:00
parent 572396625c
commit 680f916073
2 changed files with 7 additions and 0 deletions

View File

@ -4,4 +4,5 @@
BOOST_AUTO_TEST_CASE(BoostLogTest) { BOOST_AUTO_TEST_CASE(BoostLogTest) {
boost::log::initialize(); boost::log::initialize();
LOG(info) << "this is a test output."; LOG(info) << "this is a test output.";
LOG_FORMAT(info, "i am %s, %d years old.", "amass", 29);
} }

View File

@ -216,6 +216,12 @@ BOOST_LOG_GLOBAL_LOGGER(location_logger, LocationLogger<boost::log::trivial::sev
(AmassKeywords::LineTag = __LINE__) \ (AmassKeywords::LineTag = __LINE__) \
(AmassKeywords::CategoryTag = #cat)) (AmassKeywords::CategoryTag = #cat))
#define LOG_FORMAT(lvl,...)\
auto xxx_size = snprintf(nullptr,0,__VA_ARGS__);\
std::string xxx_buffer(xxx_size,'\0');\
snprintf(xxx_buffer.data(),xxx_buffer.size(),__VA_ARGS__);\
LOG(lvl)<<std::move(xxx_buffer);
// clang-format on // clang-format on
#include "BoostLog.inl" #include "BoostLog.inl"