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

[easylog][fix]treat the same with WARN/WARNING and CRITICAL/FATAL #439

Merged
merged 3 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
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
19 changes: 14 additions & 5 deletions include/ylt/easylog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ class logger {
append_format(record);
}

if (record.get_severity() == Severity::CRITICAL) {
if (record.get_severity() == Severity::CRITICAL ||
record.get_severity() == Severity::FATAL) {
flush();
std::exit(EXIT_FAILURE);
}
Expand Down Expand Up @@ -213,7 +214,8 @@ inline void add_appender(std::function<void(std::string_view)> fn) {
easylog::record_t(std::chrono::system_clock::now(), severity, \
GET_STRING(__FILE__, __LINE__)) \
.sprintf(fmt, __VA_ARGS__); \
if (severity == easylog::Severity::CRITICAL) { \
if (severity == easylog::Severity::CRITICAL || \
severity == easylog::Severity::FATAL) { \
easylog::flush<Id>(); \
std::exit(EXIT_FAILURE); \
} \
Expand All @@ -240,7 +242,8 @@ inline void add_appender(std::function<void(std::string_view)> fn) {
easylog::record_t(std::chrono::system_clock::now(), severity, \
GET_STRING(__FILE__, __LINE__)) \
.format(prefix::format(format_str, __VA_ARGS__)); \
if (severity == easylog::Severity::CRITICAL) { \
if (severity == easylog::Severity::CRITICAL || \
severity == Severity::FATAL) { \
easylog::flush<Id>(); \
std::exit(EXIT_FAILURE); \
} \
Expand Down Expand Up @@ -285,6 +288,9 @@ inline void add_appender(std::function<void(std::string_view)> fn) {
#ifndef ELOG_CRITICAL
#define ELOG_CRITICAL ELOG(CRITICAL)
#endif
#ifndef ELOG_FATAL
#define ELOG_FATAL ELOG(FATAL)
#endif

#ifndef MELOG_TRACE
#define MELOG_TRACE(id) ELOG(INFO, id)
Expand All @@ -301,8 +307,8 @@ inline void add_appender(std::function<void(std::string_view)> fn) {
#ifndef MELOG_ERROR
#define MELOG_ERROR(id) ELOG(ERROR, id)
#endif
#ifndef MELOG_CRITICAL
#define MELOG_CRITICAL(id) ELOG(CRITICAL, id)
#ifndef MELOG_FATAL
#define MELOG_FATAL(id) ELOG(FATAL, id)
#endif

#ifndef ELOGT
Expand All @@ -323,3 +329,6 @@ inline void add_appender(std::function<void(std::string_view)> fn) {
#ifndef ELOGC
#define ELOGC ELOG_CRITICAL
#endif
#ifndef ELOGF
#define ELOGF ELOG_FATAL
#endif
4 changes: 2 additions & 2 deletions include/ylt/easylog/appender.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,11 @@ class appender {

void add_color(Severity severity) {
#if defined(_WIN32)
if (severity == Severity::WARN)
if (severity == Severity::WARN || severity == Severity::WARNING)
windows_set_color(color_type::black, color_type::yellow);
if (severity == Severity::ERROR)
windows_set_color(color_type::black, color_type::red);
if (severity == Severity::CRITICAL)
if (severity == Severity::CRITICAL || severity == Severity::FATAL)
windows_set_color(color_type::white_bright, color_type::red);
#elif __APPLE__
#else
Expand Down
1 change: 0 additions & 1 deletion src/easylog/tests/test_easylog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ TEST_CASE("test basic") {

ELOG(WARN) << "warn";
ELOG(WARNING) << "warning";
ELOG(FATAL) << "fatal";

ELOG(INFO) << "test log";
easylog::flush();
Expand Down
Loading