Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

constexpr LEVELS for easier custom level usage #483

Merged
merged 1 commit into from
May 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions src/g3log/loglevels.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ struct LEVELS {
// "dynamic, runtime loading of shared libraries"

LEVELS(const LEVELS& other): value(other.value), text(other.text.c_str()) {}

#if __cplusplus >= 202002L
constexpr
#endif
LEVELS(int id, const std::string& idtext) : value(id), text(idtext) {}

bool operator==(const LEVELS& rhs) const {
Expand Down Expand Up @@ -90,11 +94,15 @@ namespace g3 {
static const int kInternalFatalValue = 2000;
} // g3


const LEVELS G3LOG_DEBUG{g3::kDebugValue, {"DEBUG"}},
INFO {g3::kInfoValue, {"INFO"}},
WARNING {g3::kWarningValue, {"WARNING"}},
FATAL {g3::kFatalValue, {"FATAL"}};
#if __cplusplus >= 202002L
constexpr
#else
const
#endif
LEVELS G3LOG_DEBUG{g3::kDebugValue, "DEBUG"},
INFO {g3::kInfoValue, "INFO"},
WARNING {g3::kWarningValue, "WARNING"},
FATAL {g3::kFatalValue, "FATAL"};



Expand Down Expand Up @@ -129,7 +137,12 @@ namespace g3 {

namespace g3 {
namespace internal {
const LEVELS CONTRACT {g3::kInternalFatalValue, {"CONTRACT"}},
#if __cplusplus >= 202002L
constexpr
#else
const
#endif
LEVELS CONTRACT {g3::kInternalFatalValue, {"CONTRACT"}},
FATAL_SIGNAL {g3::kInternalFatalValue + 1, {"FATAL_SIGNAL"}},
FATAL_EXCEPTION {kInternalFatalValue + 2, {"FATAL_EXCEPTION"}};

Expand Down