mirror of
https://github.com/gabime/spdlog.git
synced 2024-11-15 16:35:45 +08:00
Clean level names logic and inline them
This commit is contained in:
parent
3d5ddea136
commit
96bed42974
@ -13,22 +13,11 @@
|
|||||||
namespace spdlog {
|
namespace spdlog {
|
||||||
namespace level {
|
namespace level {
|
||||||
|
|
||||||
#if __cplusplus >= 201703L
|
//#if __cplusplus >= 201703L
|
||||||
constexpr
|
//constexpr
|
||||||
#endif
|
//#endif
|
||||||
static string_view_t level_string_views[] SPDLOG_LEVEL_NAMES;
|
// static string_view_t level_string_views[] SPDLOG_LEVEL_NAMES;
|
||||||
|
|
||||||
static const char *short_level_names[] SPDLOG_SHORT_LEVEL_NAMES;
|
|
||||||
|
|
||||||
SPDLOG_INLINE const string_view_t &to_string_view(spdlog::level::level_enum l) noexcept
|
|
||||||
{
|
|
||||||
return level_string_views[l];
|
|
||||||
}
|
|
||||||
|
|
||||||
SPDLOG_INLINE const char *to_short_c_str(spdlog::level::level_enum l) noexcept
|
|
||||||
{
|
|
||||||
return short_level_names[l];
|
|
||||||
}
|
|
||||||
|
|
||||||
SPDLOG_INLINE spdlog::level::level_enum from_str(const std::string &name) noexcept
|
SPDLOG_INLINE spdlog::level::level_enum from_str(const std::string &name) noexcept
|
||||||
{
|
{
|
||||||
|
@ -177,32 +177,27 @@ enum level_enum : int
|
|||||||
n_levels
|
n_levels
|
||||||
};
|
};
|
||||||
|
|
||||||
#define SPDLOG_LEVEL_NAME_TRACE spdlog::string_view_t("trace", 5)
|
|
||||||
#define SPDLOG_LEVEL_NAME_DEBUG spdlog::string_view_t("debug", 5)
|
|
||||||
#define SPDLOG_LEVEL_NAME_INFO spdlog::string_view_t("info", 4)
|
|
||||||
#define SPDLOG_LEVEL_NAME_WARNING spdlog::string_view_t("warning", 7)
|
|
||||||
#define SPDLOG_LEVEL_NAME_ERROR spdlog::string_view_t("error", 5)
|
|
||||||
#define SPDLOG_LEVEL_NAME_CRITICAL spdlog::string_view_t("critical", 8)
|
|
||||||
#define SPDLOG_LEVEL_NAME_OFF spdlog::string_view_t("off", 3)
|
|
||||||
|
|
||||||
#if !defined(SPDLOG_LEVEL_NAMES)
|
#if !defined(SPDLOG_LEVEL_NAMES)
|
||||||
# define SPDLOG_LEVEL_NAMES \
|
#define SPDLOG_LEVEL_NAMES { "trace", "debug", "info", "warning", "error", "critical", "off"}
|
||||||
{ \
|
|
||||||
SPDLOG_LEVEL_NAME_TRACE, SPDLOG_LEVEL_NAME_DEBUG, SPDLOG_LEVEL_NAME_INFO, SPDLOG_LEVEL_NAME_WARNING, SPDLOG_LEVEL_NAME_ERROR, \
|
|
||||||
SPDLOG_LEVEL_NAME_CRITICAL, SPDLOG_LEVEL_NAME_OFF \
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(SPDLOG_SHORT_LEVEL_NAMES)
|
#if !defined(SPDLOG_SHORT_LEVEL_NAMES)
|
||||||
|
#define SPDLOG_SHORT_LEVEL_NAMES {"T", "D", "I", "W", "E", "C", "O"}
|
||||||
# define SPDLOG_SHORT_LEVEL_NAMES \
|
|
||||||
{ \
|
|
||||||
"T", "D", "I", "W", "E", "C", "O" \
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
SPDLOG_API const string_view_t &to_string_view(spdlog::level::level_enum l) noexcept;
|
constexpr string_view_t level_string_views[] SPDLOG_LEVEL_NAMES;
|
||||||
SPDLOG_API const char *to_short_c_str(spdlog::level::level_enum l) noexcept;
|
constexpr const char *short_level_names[] SPDLOG_SHORT_LEVEL_NAMES;
|
||||||
|
|
||||||
|
constexpr string_view_t to_string_view(spdlog::level::level_enum lvl) noexcept
|
||||||
|
{
|
||||||
|
return level_string_views[lvl];
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr const char *to_short_c_str(spdlog::level::level_enum lvl) noexcept
|
||||||
|
{
|
||||||
|
return short_level_names[lvl];
|
||||||
|
}
|
||||||
|
|
||||||
SPDLOG_API spdlog::level::level_enum from_str(const std::string &name) noexcept;
|
SPDLOG_API spdlog::level::level_enum from_str(const std::string &name) noexcept;
|
||||||
|
|
||||||
} // namespace level
|
} // namespace level
|
||||||
|
Loading…
Reference in New Issue
Block a user