Skip to content

Commit

Permalink
Fix after public code review: use a table instead dbConnector when ac…
Browse files Browse the repository at this point in the history
…cessing the table, use static const instead define, and add white space where needed
  • Loading branch information
EdenGri committed Oct 10, 2022
1 parent 27d5202 commit 31410c3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 25 deletions.
24 changes: 4 additions & 20 deletions common/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,40 +122,24 @@ void Logger::linkToDbWithOutput(
logger.m_settingChangeObservers.insert(std::make_pair(dbName, std::make_pair(prioNotify, outputNotify)));

DBConnector db("CONFIG_DB", 0);
std::string key_prefix(CFG_LOGGER_TABLE_NAME);
key_prefix+="|";
std::string key = key_prefix + dbName;
SWSS_LOG_DEBUG("Component %s register to logger with the key: %s", dbName.c_str(), key.c_str());
swss::Table table(&db, CFG_LOGGER_TABLE_NAME);
SWSS_LOG_DEBUG("Component %s register to logger", dbName.c_str());

std::string prio, output;
bool doUpdate = false;
auto prioPtr = db.hget(key, DAEMON_LOGLEVEL);
auto outputPtr = db.hget(key, DAEMON_LOGOUTPUT);

if (prioPtr == nullptr)
if(!table.hget(dbName, DAEMON_LOGLEVEL, prio))
{
prio = defPrio;
doUpdate = true;
}
else
{
prio = *prioPtr;
}

if (outputPtr == nullptr)
if(!table.hget(dbName, DAEMON_LOGLEVEL, output))
{
output = defOutput;
doUpdate = true;

}
else
{
output = *outputPtr;
}

if (doUpdate)
{
swss::Table table(&db, CFG_LOGGER_TABLE_NAME);
FieldValueTuple fvLevel(DAEMON_LOGLEVEL, prio);
FieldValueTuple fvOutput(DAEMON_LOGOUTPUT, output);
std::vector<FieldValueTuple>fieldValues = { fvLevel, fvOutput };
Expand Down
6 changes: 3 additions & 3 deletions common/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ namespace swss {

#define SWSS_LOG_THROW(MSG, ...) swss::Logger::getInstance().wthrow(swss::Logger::SWSS_ERROR, ":- %s: " MSG, __FUNCTION__, ##__VA_ARGS__)

static constexpr const char * const DAEMON_LOGLEVEL = "LOGLEVEL";
static constexpr const char * const DAEMON_LOGOUTPUT = "LOGOUTPUT";

void err_exit(const char *fn, int ln, int e, const char *fmt, ...)
#ifdef __GNUC__
__attribute__ ((format (printf, 4, 5)))
Expand All @@ -47,9 +50,6 @@ class Logger
{
public:

#define DAEMON_LOGLEVEL "LOGLEVEL"
#define DAEMON_LOGOUTPUT "LOGOUTPUT"

enum Priority
{
SWSS_EMERG,
Expand Down
4 changes: 2 additions & 2 deletions common/loglevel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ std::vector<std::string> get_no_sai_keys(std::vector<std::string> keys)
return keys;
}

void setAllLoglevel(swss::Table& logger_tbl, std::vector<std::string> components,std::string loglevel)
void setAllLoglevel(swss::Table& logger_tbl, std::vector<std::string> components, std::string loglevel)
{
for (const auto& component : components)
{
Expand Down Expand Up @@ -194,7 +194,7 @@ int swssloglevel(int argc, char** argv)
keys.erase(std::remove_if(keys.begin(), keys.end(), filterOutSaiKeys), keys.end());
}

setAllLoglevel(logger_tbl,keys, loglevel);
setAllLoglevel(logger_tbl, keys, loglevel);
exit(EXIT_SUCCESS);
}

Expand Down

0 comments on commit 31410c3

Please sign in to comment.