Skip to content

Commit

Permalink
treat the same with WARN/WARNING and CRITICAL/FATAL (#439)
Browse files Browse the repository at this point in the history
  • Loading branch information
qicosmos authored Sep 4, 2023
1 parent b662259 commit 7cf69d1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
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

0 comments on commit 7cf69d1

Please sign in to comment.