Skip to content

Commit

Permalink
Improved the implementation of Us4R to arrus logging mechanism.
Browse files Browse the repository at this point in the history
Replaced static hashmap with switch clause.
  • Loading branch information
pjarosik committed Jan 14, 2022
1 parent 537b43f commit 4d3d0bc
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions arrus/core/devices/us4r/external/ius4oem/Us4RLoggerWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <unordered_map>
#include <utility>
#include <stdexcept>

// us4r
#include <logging/Logger.h>
Expand All @@ -14,30 +15,41 @@ namespace arrus::devices {
class Us4RLoggerWrapper : public us4r::Logger {
public:

Us4RLoggerWrapper(arrus::Logger::SharedHandle logger)
explicit Us4RLoggerWrapper(arrus::Logger::SharedHandle logger)
: logger(std::move(logger)) {}

void
log(const us4r::LogSeverity severity, const std::string &msg) override {
logger->log(sevMap.at(severity), msg);
switch(severity) {
case us4r::LogSeverity::TRACE:
logger->log(arrus::LogSeverity::TRACE, msg);
break;
case us4r::LogSeverity::DEBUG:
logger->log(arrus::LogSeverity::DEBUG, msg);
break;
case us4r::LogSeverity::INFO:
logger->log(arrus::LogSeverity::INFO, msg);
break;
case us4r::LogSeverity::WARNING:
logger->log(arrus::LogSeverity::WARNING, msg);
break;
case us4r::LogSeverity::ERROR:
logger->log(arrus::LogSeverity::ERROR, msg);
break;
case us4r::LogSeverity::FATAL:
logger->log(arrus::LogSeverity::FATAL, msg);
break;
default:
throw std::runtime_error("Unknown logging level");
}
}

void
setAttribute(const std::string &key, const std::string &value) override {
logger->setAttribute(key, value);
}

private:
arrus::Logger::SharedHandle logger;

static const inline std::unordered_map<us4r::LogSeverity, arrus::LogSeverity> sevMap{
{us4r::LogSeverity::TRACE, arrus::LogSeverity::TRACE},
{us4r::LogSeverity::DEBUG, arrus::LogSeverity::DEBUG},
{us4r::LogSeverity::INFO, arrus::LogSeverity::INFO},
{us4r::LogSeverity::WARNING, arrus::LogSeverity::WARNING},
{us4r::LogSeverity::ERROR, arrus::LogSeverity::ERROR},
{us4r::LogSeverity::FATAL, arrus::LogSeverity::FATAL},
};
};

}
Expand Down

0 comments on commit 4d3d0bc

Please sign in to comment.