mirror of
https://github.com/gabime/spdlog.git
synced 2025-01-24 22:49:05 +08:00
Merge pull request #1948 from stevenlunt/v1.x
add macros for overriding the individual level names
This commit is contained in:
commit
6ba5ab6d67
@ -235,6 +235,25 @@ if(SPDLOG_NO_EXCEPTIONS AND NOT MSVC)
|
|||||||
target_compile_options(spdlog PRIVATE -fno-exceptions)
|
target_compile_options(spdlog PRIVATE -fno-exceptions)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------------------
|
||||||
|
# Allow override of level names
|
||||||
|
# ---------------------------------------------------------------------------------------
|
||||||
|
set(SPDLOG_LEVEL_NAME_TRACE "trace" CACHE STRING "custom level name")
|
||||||
|
set(SPDLOG_LEVEL_NAME_DEBUG "debug" CACHE STRING "custom level name")
|
||||||
|
set(SPDLOG_LEVEL_NAME_INFO "info" CACHE STRING "custom level name")
|
||||||
|
set(SPDLOG_LEVEL_NAME_WARNING "warning" CACHE STRING "custom level name")
|
||||||
|
set(SPDLOG_LEVEL_NAME_ERROR "error" CACHE STRING "custom level name")
|
||||||
|
set(SPDLOG_LEVEL_NAME_CRITICAL "critical" CACHE STRING "custom level name")
|
||||||
|
set(SPDLOG_LEVEL_NAME_OFF "off" CACHE STRING "custom level name")
|
||||||
|
|
||||||
|
target_compile_definitions(spdlog PUBLIC SPDLOG_LEVEL_NAME_TRACE=\"${SPDLOG_LEVEL_NAME_TRACE}\")
|
||||||
|
target_compile_definitions(spdlog PUBLIC SPDLOG_LEVEL_NAME_DEBUG=\"${SPDLOG_LEVEL_NAME_DEBUG}\")
|
||||||
|
target_compile_definitions(spdlog PUBLIC SPDLOG_LEVEL_NAME_INFO=\"${SPDLOG_LEVEL_NAME_INFO}\")
|
||||||
|
target_compile_definitions(spdlog PUBLIC SPDLOG_LEVEL_NAME_WARNING=\"${SPDLOG_LEVEL_NAME_WARNING}\")
|
||||||
|
target_compile_definitions(spdlog PUBLIC SPDLOG_LEVEL_NAME_ERROR=\"${SPDLOG_LEVEL_NAME_ERROR}\")
|
||||||
|
target_compile_definitions(spdlog PUBLIC SPDLOG_LEVEL_NAME_CRITICAL=\"${SPDLOG_LEVEL_NAME_CRITICAL}\")
|
||||||
|
target_compile_definitions(spdlog PUBLIC SPDLOG_LEVEL_NAME_OFF=\"${SPDLOG_LEVEL_NAME_OFF}\")
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
# Build binaries
|
# Build binaries
|
||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
|
@ -13,6 +13,9 @@
|
|||||||
namespace spdlog {
|
namespace spdlog {
|
||||||
namespace level {
|
namespace level {
|
||||||
|
|
||||||
|
#if __cplusplus >= 201703L
|
||||||
|
constexpr
|
||||||
|
#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;
|
static const char *short_level_names[] SPDLOG_SHORT_LEVEL_NAMES;
|
||||||
@ -22,11 +25,6 @@ SPDLOG_INLINE const string_view_t &to_string_view(spdlog::level::level_enum l) S
|
|||||||
return level_string_views[l];
|
return level_string_views[l];
|
||||||
}
|
}
|
||||||
|
|
||||||
SPDLOG_INLINE void set_string_view(spdlog::level::level_enum l, const string_view_t &s) SPDLOG_NOEXCEPT
|
|
||||||
{
|
|
||||||
level_string_views[l] = s;
|
|
||||||
}
|
|
||||||
|
|
||||||
SPDLOG_INLINE const char *to_short_c_str(spdlog::level::level_enum l) SPDLOG_NOEXCEPT
|
SPDLOG_INLINE const char *to_short_c_str(spdlog::level::level_enum l) SPDLOG_NOEXCEPT
|
||||||
{
|
{
|
||||||
return short_level_names[l];
|
return short_level_names[l];
|
||||||
|
@ -152,10 +152,38 @@ enum level_enum
|
|||||||
n_levels
|
n_levels
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if !defined(SPDLOG_LEVEL_NAME_TRACE)
|
||||||
|
#define SPDLOG_LEVEL_NAME_TRACE "trace"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(SPDLOG_LEVEL_NAME_DEBUG)
|
||||||
|
#define SPDLOG_LEVEL_NAME_DEBUG "debug"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(SPDLOG_LEVEL_NAME_INFO)
|
||||||
|
#define SPDLOG_LEVEL_NAME_INFO "info"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(SPDLOG_LEVEL_NAME_WARNING)
|
||||||
|
#define SPDLOG_LEVEL_NAME_WARNING "warning"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(SPDLOG_LEVEL_NAME_ERROR)
|
||||||
|
#define SPDLOG_LEVEL_NAME_ERROR "error"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(SPDLOG_LEVEL_NAME_CRITICAL)
|
||||||
|
#define SPDLOG_LEVEL_NAME_CRITICAL "critical"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(SPDLOG_LEVEL_NAME_OFF)
|
||||||
|
#define SPDLOG_LEVEL_NAME_OFF "off"
|
||||||
|
#endif
|
||||||
|
|
||||||
#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
|
||||||
|
|
||||||
@ -168,7 +196,6 @@ enum level_enum
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
SPDLOG_API const string_view_t &to_string_view(spdlog::level::level_enum l) SPDLOG_NOEXCEPT;
|
SPDLOG_API const string_view_t &to_string_view(spdlog::level::level_enum l) SPDLOG_NOEXCEPT;
|
||||||
SPDLOG_API void set_string_view(spdlog::level::level_enum l, const string_view_t &s) SPDLOG_NOEXCEPT;
|
|
||||||
SPDLOG_API const char *to_short_c_str(spdlog::level::level_enum l) SPDLOG_NOEXCEPT;
|
SPDLOG_API const char *to_short_c_str(spdlog::level::level_enum l) SPDLOG_NOEXCEPT;
|
||||||
SPDLOG_API spdlog::level::level_enum from_str(const std::string &name) SPDLOG_NOEXCEPT;
|
SPDLOG_API spdlog::level::level_enum from_str(const std::string &name) SPDLOG_NOEXCEPT;
|
||||||
|
|
||||||
|
@ -87,12 +87,54 @@
|
|||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// Uncomment to customize level names (e.g. "MT TRACE")
|
// Uncomment to customize level names (e.g. "MY TRACE")
|
||||||
//
|
//
|
||||||
// #define SPDLOG_LEVEL_NAMES { "MY TRACE", "MY DEBUG", "MY INFO", "MY WARNING",
|
// #define SPDLOG_LEVEL_NAMES { "MY TRACE", "MY DEBUG", "MY INFO", "MY WARNING",
|
||||||
// "MY ERROR", "MY CRITICAL", "OFF" }
|
// "MY ERROR", "MY CRITICAL", "OFF" }
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Uncomment to customize the trace level name
|
||||||
|
//
|
||||||
|
// #define SPDLOG_LEVEL_NAME_TRACE "MY TRACE"
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Uncomment to customize the debug level name
|
||||||
|
//
|
||||||
|
// #define SPDLOG_LEVEL_NAME_DEBUG "MY DEBUG"
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Uncomment to customize the info level name
|
||||||
|
//
|
||||||
|
// #define SPDLOG_LEVEL_NAME_INFO "MY INFO"
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Uncomment to customize the warning level name
|
||||||
|
//
|
||||||
|
// #define SPDLOG_LEVEL_NAME_WARNING "MY WARNING"
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Uncomment to customize the error level name
|
||||||
|
//
|
||||||
|
// #define SPDLOG_LEVEL_NAME_ERROR "MY ERROR"
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Uncomment to customize the critical level name
|
||||||
|
//
|
||||||
|
// #define SPDLOG_LEVEL_NAME_CRITICAL "MY CRITICAL"
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Uncomment to customize the off level name
|
||||||
|
//
|
||||||
|
// #define SPDLOG_LEVEL_NAME_OFF "MY OFF"
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// Uncomment to customize short level names (e.g. "MT")
|
// Uncomment to customize short level names (e.g. "MT")
|
||||||
// These can be longer than one character.
|
// These can be longer than one character.
|
||||||
|
@ -55,14 +55,6 @@ TEST_CASE("level_to_string_view", "[convert_to_string_view")
|
|||||||
REQUIRE(spdlog::level::to_string_view(spdlog::level::off) == "off");
|
REQUIRE(spdlog::level::to_string_view(spdlog::level::off) == "off");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("set_level_to_string_view", "[set_string_view")
|
|
||||||
{
|
|
||||||
spdlog::level::set_string_view(spdlog::level::info, "INF");
|
|
||||||
REQUIRE(spdlog::level::to_string_view(spdlog::level::info) == "INF");
|
|
||||||
spdlog::level::set_string_view(spdlog::level::info, "info"); // set it back
|
|
||||||
REQUIRE(spdlog::level::to_string_view(spdlog::level::info) == "info");
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("to_short_c_str", "[convert_to_short_c_str]")
|
TEST_CASE("to_short_c_str", "[convert_to_short_c_str]")
|
||||||
{
|
{
|
||||||
REQUIRE(std::string(spdlog::level::to_short_c_str(spdlog::level::trace)) == "T");
|
REQUIRE(std::string(spdlog::level::to_short_c_str(spdlog::level::trace)) == "T");
|
||||||
|
Loading…
Reference in New Issue
Block a user