Skip to content

Commit

Permalink
log_level_from_value function
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkvdb committed Dec 17, 2024
1 parent c5bd48b commit 3fc42f3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions include/infra/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,4 +290,6 @@ struct LogRegistration
Log::uninitialize();
}
};

Log::Level log_level_from_value(int32_t value);
}
20 changes: 19 additions & 1 deletion log.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "infra/log.h"
#include "infra/exception.h"
#include "infra/string.h"

#include <spdlog/async.h>
Expand Down Expand Up @@ -95,7 +96,6 @@ void Log::initialize_async(const std::string& name)
_log = std::make_shared<spdlog::async_logger>(name, begin(_sinks), end(_sinks), spdlog::thread_pool(), spdlog::async_overflow_policy::block);
_log->set_pattern("%^[%L] %v%$");
_log->set_level(spdlog::level::warn);

}

void Log::uninitialize()
Expand Down Expand Up @@ -143,4 +143,22 @@ void Log::set_pattern(std::string_view pattern)
{
_log->set_pattern(fmt::format("%^{}%$", pattern));
}

Log::Level log_level_from_value(int32_t value)
{
switch (value) {
case 1:
return Log::Level::Debug;
case 2:
return Log::Level::Info;
case 3:
return Log::Level::Warning;
case 4:
return Log::Level::Error;
case 5:
return Log::Level::Critical;
default:
throw RuntimeError("Invalid log level specified '{}': value must be in range [1-5]", value);
}
}
}

0 comments on commit 3fc42f3

Please sign in to comment.