From c6bbb0a83248140132e83ce498a087b224812d91 Mon Sep 17 00:00:00 2001 From: Matt Aber Date: Wed, 22 May 2024 17:34:30 -0400 Subject: [PATCH] Support inline sink patterns Change-Id: I3da32c5b7cc7f00fea29c612b0b5e5a8a2fa5881 --- src/KDSpdSetup/kdspdsetup.cpp | 2 +- src/KDSpdSetup/setup.cpp | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/KDSpdSetup/kdspdsetup.cpp b/src/KDSpdSetup/kdspdsetup.cpp index c0fa19e..bf5f5bb 100644 --- a/src/KDSpdSetup/kdspdsetup.cpp +++ b/src/KDSpdSetup/kdspdsetup.cpp @@ -17,8 +17,8 @@ void setupFrom(std::string const &file) { auto const data = toml::parse(file); - setup::setupSinks(data); setup::setupPatterns(data); + setup::setupSinks(data); setup::setupThreadPools(data); setup::setupLoggers(data); } diff --git a/src/KDSpdSetup/setup.cpp b/src/KDSpdSetup/setup.cpp index 605c2b2..dff33a1 100644 --- a/src/KDSpdSetup/setup.cpp +++ b/src/KDSpdSetup/setup.cpp @@ -59,10 +59,16 @@ void setupSink(toml::table &&sinkTable) throw std::out_of_range("KDSPDSetup: sink type "s + typeStr.str + " is not valid"s); toml::string level = ""; + toml::string pattern = ""; + if (sinkTable.contains("level")) { level = sinkTable.at("level").as_string(); } + if (sinkTable.contains("pattern")) { + pattern = sinkTable.at("pattern").as_string(); + } + if (details::inTypelist(typeStr, details::fileStrs) || details::inTypelist(typeStr, details::rotateStrs) || details::inTypelist(typeStr, details::dailyStrs)) { handleTruncatableSink(std::move(typeStr), std::move(sinkTable), sinkPtr); @@ -93,6 +99,14 @@ void setupSink(toml::table &&sinkTable) sinkPtr->set_level(details::levelMap.at(level)); } + if (pattern != "") { + if (details::SPDMaps::patternMap().contains(pattern)) { + sinkPtr->set_pattern(details::SPDMaps::patternMap().at(pattern)); + } else { + sinkPtr->set_pattern(pattern); + } + } + details::SPDMaps::emplaceSinkMap(std::make_pair(name, sinkPtr)); }