From 8696ad8739ae35b9caf290c6905c713d5fd00378 Mon Sep 17 00:00:00 2001 From: fegomes Date: Wed, 24 Jan 2018 23:08:46 -0200 Subject: [PATCH] new function to convert level_enum from string --- include/spdlog/common.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/spdlog/common.h b/include/spdlog/common.h index ea0b0567..339e8b29 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -51,6 +51,9 @@ namespace spdlog class formatter; +template +constexpr size_t size(T(&)[N]) { return N; } + namespace sinks { class sink; @@ -98,6 +101,18 @@ inline const char* to_short_str(spdlog::level::level_enum l) { return short_level_names[l]; } +inline spdlog::level::level_enum to_level_enum(const char* name) +{ + for (size_t level = 0; level < size(level_names); level++) + { + if (!strcmp(level_names[level], name)) + { + return (spdlog::level::level_enum) level; + } + } + return (spdlog::level::level_enum) 0; +} + } //level