Skip to content

Commit

Permalink
Merge pull request #495 from ami-iit/fmt_8_1_1
Browse files Browse the repository at this point in the history
Use enum underlying type to convert TextLogging verbosity level to spdlog verbosity level
  • Loading branch information
GiulioRomualdi authored Jan 10, 2022
2 parents 0a758c5 + e47ede4 commit a8bd56a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ All notable changes to this project are documented in this file.
- Reduce code duplication in python bindings (https://github.com/ami-iit/bipedal-locomotion-framework/pull/484)
- Use `TextLogger` in `YarpRobotLoggerDevice` instead of `yarp` commands (https://github.com/ami-iit/bipedal-locomotion-framework/pull/486)
- Ask for `osqp-eigen 0.6.4.100`(https://github.com/ami-iit/bipedal-locomotion-framework/pull/490)
- Use enum underlying type to convert `TextLogging` verbosity level to `spdlog` verbosity level (https://github.com/ami-iit/bipedal-locomotion-framework/pull/495)

### Fix
- Fix the population of the jointAccelerations and baseAcceleration variables in QPTSID (https://github.com/ami-iit/bipedal-locomotion-framework/pull/478)
Expand Down
17 changes: 9 additions & 8 deletions src/TextLogging/include/BipedalLocomotion/TextLogging/Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <spdlog/fmt/ostr.h>

#include <spdlog/spdlog.h>
#include <type_traits>

namespace BipedalLocomotion
{
Expand All @@ -35,15 +36,15 @@ namespace BipedalLocomotion
{
namespace TextLogging
{
enum class Verbosity
enum class Verbosity : std::underlying_type<spdlog::level::level_enum>::type
{
Trace,
Debug,
Info,
Warn,
Err,
Critical,
Off,
Trace = static_cast<std::underlying_type<spdlog::level::level_enum>::type>(spdlog::level::level_enum::trace),
Debug = static_cast<std::underlying_type<spdlog::level::level_enum>::type>(spdlog::level::level_enum::debug),
Info = static_cast<std::underlying_type<spdlog::level::level_enum>::type>(spdlog::level::level_enum::info),
Warn = static_cast<std::underlying_type<spdlog::level::level_enum>::type>(spdlog::level::level_enum::warn),
Err = static_cast<std::underlying_type<spdlog::level::level_enum>::type>(spdlog::level::level_enum::err),
Critical = static_cast<std::underlying_type<spdlog::level::level_enum>::type>(spdlog::level::level_enum::critical),
Off = static_cast<std::underlying_type<spdlog::level::level_enum>::type>(spdlog::level::level_enum::off),
};

/**
Expand Down
20 changes: 3 additions & 17 deletions src/TextLogging/src/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,9 @@ TextLogging::Logger* const log()

void TextLogging::setVerbosity(const Verbosity verbosity)
{
const std::unordered_map<TextLogging::Verbosity, spdlog::level::level_enum> map{
{TextLogging::Verbosity::Trace, spdlog::level::level_enum::trace},
{TextLogging::Verbosity::Debug, spdlog::level::level_enum::debug},
{TextLogging::Verbosity::Info, spdlog::level::level_enum::info},
{TextLogging::Verbosity::Warn, spdlog::level::level_enum::warn},
{TextLogging::Verbosity::Err, spdlog::level::level_enum::err},
{TextLogging::Verbosity::Critical, spdlog::level::level_enum::critical},
{TextLogging::Verbosity::Off, spdlog::level::level_enum::off},
};

if (map.find(verbosity) == map.end())
{
log()->error("Failed to change verbosity to level {}", verbosity);
return;
}

log()->set_level(map.at(verbosity));
// get the verbosity underling value and convert it in spdlog enum type
const auto value = static_cast<std::underlying_type<Verbosity>::type>(verbosity);
log()->set_level(static_cast<spdlog::level::level_enum>(value));
}

} // namespace BipedalLocomotion

0 comments on commit a8bd56a

Please sign in to comment.