diff --git a/common/dbinterface.cpp b/common/dbinterface.cpp index dc86ffade..dc1ea6f6b 100644 --- a/common/dbinterface.cpp +++ b/common/dbinterface.cpp @@ -106,7 +106,7 @@ std::vector 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"); } diff --git a/common/logger.h b/common/logger.h index 74d6f7992..145889843 100644 --- a/common/logger.h +++ b/common/logger.h @@ -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 { @@ -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 m_currentPrios; diff --git a/pyext/swsscommon.i b/pyext/swsscommon.i index d41fcfc03..b3731b737 100644 --- a/pyext/swsscommon.i +++ b/pyext/swsscommon.i @@ -23,6 +23,7 @@ #include "notificationconsumer.h" #include "notificationproducer.h" #include "warm_restart.h" +#include "logger.h" %} %include @@ -137,3 +138,4 @@ T castSelectableObj(swss::Selectable *temp) %include "notificationproducer.h" %include "warm_restart.h" %include "dbinterface.h" +%include "logger.h" diff --git a/tests/test_logger.py b/tests/test_logger.py new file mode 100644 index 000000000..178dc274e --- /dev/null +++ b/tests/test_logger.py @@ -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