Skip to content

Commit d458a11

Browse files
committed
[syncd] Move set api log level to Syncd class
1 parent cee2e01 commit d458a11

File tree

3 files changed

+61
-66
lines changed

3 files changed

+61
-66
lines changed

syncd/Syncd.cpp

+55
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ void get_port_related_objects(
7676

7777
using namespace syncd;
7878
using namespace saimeta;
79+
using namespace std::placeholders;
7980

8081
Syncd::Syncd(
8182
_In_ std::shared_ptr<sairedis::SaiInterface> vendorSai,
@@ -89,6 +90,8 @@ Syncd::Syncd(
8990
{
9091
SWSS_LOG_ENTER();
9192

93+
setSaiApiLogLevel();
94+
9295
m_manager = std::make_shared<FlexCounterManager>();
9396

9497
m_profileIter = m_profileMap.begin();
@@ -3131,3 +3134,55 @@ void Syncd::sendShutdownRequestAfterException()
31313134
}
31323135
}
31333136

3137+
void Syncd::saiLoglevelNotify(
3138+
_In_ std::string strApi,
3139+
_In_ std::string strLogLevel)
3140+
{
3141+
SWSS_LOG_ENTER();
3142+
3143+
try
3144+
{
3145+
sai_log_level_t logLevel;
3146+
sai_deserialize_log_level(strLogLevel, logLevel);
3147+
3148+
sai_api_t api;
3149+
sai_deserialize_api(strApi, api);
3150+
3151+
sai_status_t status = m_vendorSai->logSet(api, logLevel);
3152+
3153+
if (status == SAI_STATUS_SUCCESS)
3154+
{
3155+
SWSS_LOG_NOTICE("Setting SAI loglevel %s on %s", strLogLevel.c_str(), strApi.c_str());
3156+
}
3157+
else
3158+
{
3159+
SWSS_LOG_INFO("set loglevel failed: %s", sai_serialize_status(status).c_str());
3160+
}
3161+
}
3162+
catch (const std::exception& e)
3163+
{
3164+
SWSS_LOG_ERROR("Failed to set loglevel to %s on %s: %s",
3165+
strLogLevel.c_str(),
3166+
strApi.c_str(),
3167+
e.what());
3168+
}
3169+
}
3170+
3171+
void Syncd::setSaiApiLogLevel()
3172+
{
3173+
SWSS_LOG_ENTER();
3174+
3175+
// We start from 1 since 0 is SAI_API_UNSPECIFIED.
3176+
3177+
for (uint32_t idx = 1; idx < sai_metadata_enum_sai_api_t.valuescount; ++idx)
3178+
{
3179+
// NOTE: link to db is singleton, so if we would want multiple Syncd
3180+
// instances running at the same process, we need to have logger
3181+
// registrar similar to net link messages
3182+
3183+
swss::Logger::linkToDb(
3184+
sai_metadata_enum_sai_api_t.valuesnames[idx],
3185+
std::bind(&Syncd::saiLoglevelNotify, this, _1, _2),
3186+
sai_serialize_log_level(SAI_LOG_LEVEL_NOTICE));
3187+
}
3188+
}

syncd/Syncd.h

+6
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ namespace syncd
8080

8181
void loadProfileMap();
8282

83+
void saiLoglevelNotify(
84+
_In_ std::string strApi,
85+
_In_ std::string strLogLevel);
86+
87+
void setSaiApiLogLevel();
88+
8389
private:
8490

8591
sai_status_t processNotifySyncd(

syncd/syncd.cpp

-66
Original file line numberDiff line numberDiff line change
@@ -184,68 +184,6 @@ bool isVeryFirstRun()
184184
return firstRun;
185185
}
186186

187-
static void saiLoglevelNotify(
188-
_In_ std::string strApi,
189-
_In_ std::string strLogLevel)
190-
{
191-
SWSS_LOG_ENTER();
192-
193-
try
194-
{
195-
sai_log_level_t logLevel;
196-
sai_deserialize_log_level(strLogLevel, logLevel);
197-
198-
sai_api_t api;
199-
sai_deserialize_api(strApi, api);
200-
201-
sai_status_t status = g_vendorSai->logSet(api, logLevel);
202-
203-
if (status == SAI_STATUS_SUCCESS)
204-
{
205-
SWSS_LOG_NOTICE("Setting SAI loglevel %s on %s", strLogLevel.c_str(), strApi.c_str());
206-
}
207-
else
208-
{
209-
SWSS_LOG_INFO("set loglevel failed: %s", sai_serialize_status(status).c_str());
210-
}
211-
}
212-
catch (const std::exception& e)
213-
{
214-
SWSS_LOG_ERROR("Failed to set loglevel to %s on %s: %s",
215-
strLogLevel.c_str(),
216-
strApi.c_str(),
217-
e.what());
218-
}
219-
}
220-
221-
void set_sai_api_loglevel()
222-
{
223-
SWSS_LOG_ENTER();
224-
225-
// We start from 1 since 0 is SAI_API_UNSPECIFIED.
226-
227-
for (uint32_t idx = 1; idx < sai_metadata_enum_sai_api_t.valuescount; ++idx)
228-
{
229-
// TODO std::function<void(void)> f = std::bind(&Foo::doSomething, this);
230-
swss::Logger::linkToDb(
231-
sai_metadata_enum_sai_api_t.valuesnames[idx],
232-
saiLoglevelNotify,
233-
sai_serialize_log_level(SAI_LOG_LEVEL_NOTICE));
234-
}
235-
}
236-
237-
void set_sai_api_log_min_prio(const std::string &prioStr)
238-
{
239-
SWSS_LOG_ENTER();
240-
241-
// We start from 1 since 0 is SAI_API_UNSPECIFIED.
242-
243-
for (uint32_t idx = 1; idx < sai_metadata_enum_sai_api_t.valuescount; ++idx)
244-
{
245-
const auto& api_name = sai_metadata_enum_sai_api_t.valuesnames[idx];
246-
saiLoglevelNotify(api_name, prioStr);
247-
}
248-
}
249187

250188
void timerWatchdogCallback(
251189
_In_ int64_t span)
@@ -276,8 +214,6 @@ void redisClearRidToVidMap()
276214
*/
277215
bool enableRefernceCountLogs = false;
278216

279-
extern std::shared_ptr<Syncd> g_syncd;
280-
281217
int syncd_main(int argc, char **argv)
282218
{
283219
swss::Logger::getInstance().setMinPrio(swss::Logger::SWSS_DEBUG);
@@ -286,8 +222,6 @@ int syncd_main(int argc, char **argv)
286222

287223
swss::Logger::getInstance().setMinPrio(swss::Logger::SWSS_NOTICE);
288224

289-
set_sai_api_loglevel();
290-
291225
swss::Logger::linkToDbNative("syncd"); // TODO fix also in discovery
292226

293227
swss::WarmStart::initialize("syncd", "syncd");

0 commit comments

Comments
 (0)