Commit ac7b93df authored by Nguyen, Thien's avatar Nguyen, Thien
Browse files

Added logging level getter


Signed-off-by: Nguyen, Thien's avatarThien Nguyen <nguyentm@ornl.gov>
parent 227da88c
......@@ -270,6 +270,18 @@ void XACCLogger::setLoggingLevel(int level) {
}
}
int XACCLogger::getLoggingLevel() const {
const auto spdLevel = getLogger()->level();
switch (spdLevel)
{
case spdlog::level::trace:
case spdlog::level::debug: return 2;
case spdlog::level::info: return 1;
default:
return 0;
}
}
void XACCLogger::info(const std::string &msg, MessagePredicate predicate) {
if (useCout) {
if (predicate() && globalPredicate()) {
......
......@@ -177,6 +177,10 @@ protected:
return useFile ? fileLogger : stdOutLogger;
}
std::shared_ptr<const spdlog::logger> getLogger() const {
return std::const_pointer_cast<spdlog::logger>(getLogger());
}
// On-demand create a file logger:
// We don't want to create one if not being used.
void createFileLogger();
......@@ -201,7 +205,8 @@ public:
// 2: Debug and above
// Note: this will only take effect when xacc::verbose is set.
void setLoggingLevel(int level);
int getLoggingLevel() const;
void subscribeLoggingLevel(LoggingLevelNotification onLevelChangeFn) {
loggingLevelSubscribers.emplace_back(onLevelChangeFn);
}
......
......@@ -119,6 +119,10 @@ void setLoggingLevel(int level) {
XACCLogger::instance()->setLoggingLevel(level);
}
int getLoggingLevel() {
return XACCLogger::instance()->getLoggingLevel();
}
void subscribeLoggingLevel(LoggingLevelNotification callback) {
XACCLogger::instance()->subscribeLoggingLevel(callback);
}
......
......@@ -97,6 +97,7 @@ void addCommandLineOptions(const std::map<std::string, std::string> &options);
void setGlobalLoggerPredicate(MessagePredicate predicate);
void logToFile(bool enable);
void setLoggingLevel(int level);
int getLoggingLevel();
void subscribeLoggingLevel(LoggingLevelNotification callback);
void info(const std::string &msg,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment