Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[swig] wrap logger.h #418

Merged
merged 4 commits into from
Nov 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion common/dbinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ std::vector<std::string> DBInterface::keys(const std::string& dbName, const char
auto keys = m_redisClient.at(dbName).keys(pattern);
if (keys.empty())
{
std::string message = "DB '{" + dbName + "}' is empty!";
std::string message = "DB '{" + dbName + "}' is empty with pattern '" + pattern + "'!";
SWSS_LOG_WARN("%s", message.c_str());
throw UnavailableDataError(message, "hset");
}
Expand Down
8 changes: 7 additions & 1 deletion common/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ void err_exit(const char *fn, int ln, int e, const char *fmt, ...)
err_exit(__FUNCTION__, __LINE__, e, (fmt), ##args); \
}

#ifdef __GNUC__
# define ATTRIBUTE_NORTEURN __attribute__ ((noreturn))
#else
# define ATTRIBUTE_NORTEURN
#endif

class Logger
{
Expand Down Expand Up @@ -130,7 +135,8 @@ class Logger

static void swssPrioNotify(const std::string &component, const std::string &prioStr);
static void swssOutputNotify(const std::string &component, const std::string &outputStr);
[[ noreturn ]] void settingThread();

ATTRIBUTE_NORTEURN void settingThread();

LogSettingChangeObservers m_settingChangeObservers;
std::map<std::string, std::string> m_currentPrios;
Expand Down
2 changes: 2 additions & 0 deletions pyext/swsscommon.i
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "notificationconsumer.h"
#include "notificationproducer.h"
#include "warm_restart.h"
#include "logger.h"
%}

%include <std_string.i>
Expand Down Expand Up @@ -137,3 +138,4 @@ T castSelectableObj(swss::Selectable *temp)
%include "notificationproducer.h"
%include "warm_restart.h"
%include "dbinterface.h"
%include "logger.h"
10 changes: 10 additions & 0 deletions tests/test_logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from swsscommon import swsscommon

def test_set_log_level():
swsscommon.Logger.getInstance().setMinPrio(swsscommon.Logger.SWSS_INFO)
level = swsscommon.Logger.getInstance().getMinPrio()
assert level == swsscommon.Logger.SWSS_INFO

swsscommon.Logger.getInstance().setMinPrio(swsscommon.Logger.SWSS_ERROR)
level = swsscommon.Logger.getInstance().getMinPrio()
assert level == swsscommon.Logger.SWSS_ERROR