From 9d4450d51a161d4d34720c543996d1bc60fb94b5 Mon Sep 17 00:00:00 2001 From: HanishKVC Date: Sat, 11 May 2024 19:43:34 +0530 Subject: [PATCH] GroupKV: Let dump return a string, rather than printing/logging --- common/groupkv.hpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/common/groupkv.hpp b/common/groupkv.hpp index fbaa9dcba..e6a94f3c4 100644 --- a/common/groupkv.hpp +++ b/common/groupkv.hpp @@ -116,16 +116,19 @@ public: // Dump info about the specified group. // If group is empty, then dump info about all groups maintained in this instance. - void dump(const std::string &group) { + std::string dump(const std::string &group, const std::string &msgTag = "") { + std::stringstream ss; for (auto gm: gkv) { if (!group.empty() && (gm.first != group)) { - LINFO_LN("INFO:GKV:%s:%s:Skipping...", __func__, gm.first.c_str()); + LDBUG_LN("DBUG:GKV:%s:%s:%s:Skipping...", __func__, msgTag.c_str(), gm.first.c_str()); continue; } + ss << "\n" << msgTag << gm.first << ":\n"; for(auto k: gm.second) { - LINFO_LN("DBUG:GKV:%s:%s:Iterate:%s:%s", __func__, gm.first.c_str(), k.first.c_str(), to_str(k.second).c_str()); + ss << msgTag << "\t" << k.first << ":" << to_str(k.second) << "\n"; } } + return ss.str(); } template @@ -185,7 +188,7 @@ void gkv_inited() { }}; std::cout << "**** gkv inited **** " << std::endl; - gkv.dump(""); + std::cout << gkv.dump("", "INFO:GKV:Inited:") << std::endl; } @@ -193,7 +196,7 @@ void gkv_set() { std::cout << "**** gkv set **** " << std::endl; GroupKV gkv = {{}}; - gkv.dump(""); + std::cout << gkv.dump("", "INFO:GKV:Set:Initial:") << std::endl; gkv.get_value("testme", {"key101b"}, false); gkv.get_value("testme", {"key101s"}, "Not found"); @@ -205,7 +208,7 @@ void gkv_set() { gkv.set_value("testme", {"key201i"}, 987654); gkv.set_value("testme", {"key201d"}, 9988.7766); - gkv.dump("testme"); + std::cout << gkv.dump("testme", "INFO:GKV:Set:After testme set:") << std::endl; gkv.get_value("testme", {"key201b"}, false); gkv.get_value("testme", {"key201s"}, "Not found"); gkv.get_value("testme", {"key201i"}, 123456);