Skip to content

Commit

Permalink
[syncd] Move set api log level to Syncd class
Browse files Browse the repository at this point in the history
  • Loading branch information
kcudnik committed Feb 24, 2020
1 parent cee2e01 commit d458a11
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 66 deletions.
55 changes: 55 additions & 0 deletions syncd/Syncd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ void get_port_related_objects(

using namespace syncd;
using namespace saimeta;
using namespace std::placeholders;

Syncd::Syncd(
_In_ std::shared_ptr<sairedis::SaiInterface> vendorSai,
Expand All @@ -89,6 +90,8 @@ Syncd::Syncd(
{
SWSS_LOG_ENTER();

setSaiApiLogLevel();

m_manager = std::make_shared<FlexCounterManager>();

m_profileIter = m_profileMap.begin();
Expand Down Expand Up @@ -3131,3 +3134,55 @@ void Syncd::sendShutdownRequestAfterException()
}
}

void Syncd::saiLoglevelNotify(
_In_ std::string strApi,
_In_ std::string strLogLevel)
{
SWSS_LOG_ENTER();

try
{
sai_log_level_t logLevel;
sai_deserialize_log_level(strLogLevel, logLevel);

sai_api_t api;
sai_deserialize_api(strApi, api);

sai_status_t status = m_vendorSai->logSet(api, logLevel);

if (status == SAI_STATUS_SUCCESS)
{
SWSS_LOG_NOTICE("Setting SAI loglevel %s on %s", strLogLevel.c_str(), strApi.c_str());
}
else
{
SWSS_LOG_INFO("set loglevel failed: %s", sai_serialize_status(status).c_str());
}
}
catch (const std::exception& e)
{
SWSS_LOG_ERROR("Failed to set loglevel to %s on %s: %s",
strLogLevel.c_str(),
strApi.c_str(),
e.what());
}
}

void Syncd::setSaiApiLogLevel()
{
SWSS_LOG_ENTER();

// We start from 1 since 0 is SAI_API_UNSPECIFIED.

for (uint32_t idx = 1; idx < sai_metadata_enum_sai_api_t.valuescount; ++idx)
{
// NOTE: link to db is singleton, so if we would want multiple Syncd
// instances running at the same process, we need to have logger
// registrar similar to net link messages

swss::Logger::linkToDb(
sai_metadata_enum_sai_api_t.valuesnames[idx],
std::bind(&Syncd::saiLoglevelNotify, this, _1, _2),
sai_serialize_log_level(SAI_LOG_LEVEL_NOTICE));
}
}
6 changes: 6 additions & 0 deletions syncd/Syncd.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ namespace syncd

void loadProfileMap();

void saiLoglevelNotify(
_In_ std::string strApi,
_In_ std::string strLogLevel);

void setSaiApiLogLevel();

private:

sai_status_t processNotifySyncd(
Expand Down
66 changes: 0 additions & 66 deletions syncd/syncd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,68 +184,6 @@ bool isVeryFirstRun()
return firstRun;
}

static void saiLoglevelNotify(
_In_ std::string strApi,
_In_ std::string strLogLevel)
{
SWSS_LOG_ENTER();

try
{
sai_log_level_t logLevel;
sai_deserialize_log_level(strLogLevel, logLevel);

sai_api_t api;
sai_deserialize_api(strApi, api);

sai_status_t status = g_vendorSai->logSet(api, logLevel);

if (status == SAI_STATUS_SUCCESS)
{
SWSS_LOG_NOTICE("Setting SAI loglevel %s on %s", strLogLevel.c_str(), strApi.c_str());
}
else
{
SWSS_LOG_INFO("set loglevel failed: %s", sai_serialize_status(status).c_str());
}
}
catch (const std::exception& e)
{
SWSS_LOG_ERROR("Failed to set loglevel to %s on %s: %s",
strLogLevel.c_str(),
strApi.c_str(),
e.what());
}
}

void set_sai_api_loglevel()
{
SWSS_LOG_ENTER();

// We start from 1 since 0 is SAI_API_UNSPECIFIED.

for (uint32_t idx = 1; idx < sai_metadata_enum_sai_api_t.valuescount; ++idx)
{
// TODO std::function<void(void)> f = std::bind(&Foo::doSomething, this);
swss::Logger::linkToDb(
sai_metadata_enum_sai_api_t.valuesnames[idx],
saiLoglevelNotify,
sai_serialize_log_level(SAI_LOG_LEVEL_NOTICE));
}
}

void set_sai_api_log_min_prio(const std::string &prioStr)
{
SWSS_LOG_ENTER();

// We start from 1 since 0 is SAI_API_UNSPECIFIED.

for (uint32_t idx = 1; idx < sai_metadata_enum_sai_api_t.valuescount; ++idx)
{
const auto& api_name = sai_metadata_enum_sai_api_t.valuesnames[idx];
saiLoglevelNotify(api_name, prioStr);
}
}

void timerWatchdogCallback(
_In_ int64_t span)
Expand Down Expand Up @@ -276,8 +214,6 @@ void redisClearRidToVidMap()
*/
bool enableRefernceCountLogs = false;

extern std::shared_ptr<Syncd> g_syncd;

int syncd_main(int argc, char **argv)
{
swss::Logger::getInstance().setMinPrio(swss::Logger::SWSS_DEBUG);
Expand All @@ -286,8 +222,6 @@ int syncd_main(int argc, char **argv)

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

set_sai_api_loglevel();

swss::Logger::linkToDbNative("syncd"); // TODO fix also in discovery

swss::WarmStart::initialize("syncd", "syncd");
Expand Down

0 comments on commit d458a11

Please sign in to comment.