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][feat]add more Severity, fix mac console color #418

Merged
merged 1 commit into from
Aug 19, 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
6 changes: 4 additions & 2 deletions include/ylt/easylog/appender.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,13 @@ class appender {
windows_set_color(color_type::black, color_type::red);
if (severity == Severity::CRITICAL)
windows_set_color(color_type::white_bright, color_type::red);
#elif __APPLE__
#else
if (severity == Severity::WARN)
if (severity == Severity::WARN || severity == Severity::WARNING)
std::cout << "\x1B[93m";
if (severity == Severity::ERROR)
std::cout << "\x1B[91m";
if (severity == Severity::CRITICAL)
if (severity == Severity::CRITICAL || severity == Severity::FATAL)
std::cout << "\x1B[97m\x1B[41m";
#endif
}
Expand All @@ -262,6 +263,7 @@ class appender {
#if defined(_WIN32)
if (severity >= Severity::WARN)
windows_set_color(color_type::white, color_type::black);
#elif __APPLE__
#else
if (severity >= Severity::WARN)
std::cout << "\x1B[0m\x1B[0K";
Expand Down
8 changes: 6 additions & 2 deletions include/ylt/easylog/record.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ enum class Severity {
DEBUG = 2,
INFO = 3,
WARN = 4,
ERROR = 5,
CRITICAL = 6,
WARNING = 5,
ERROR = 6,
CRITICAL = 7,
FATAL = 8,
};

inline std::string_view severity_str(Severity severity) {
Expand All @@ -99,10 +101,12 @@ inline std::string_view severity_str(Severity severity) {
case Severity::INFO:
return "INFO ";
case Severity::WARN:
case Severity::WARNING:
return "WARNING ";
case Severity::ERROR:
return "ERROR ";
case Severity::CRITICAL:
case Severity::FATAL:
return "CRITICAL";
default:
return "NONE ";
Expand Down
4 changes: 4 additions & 0 deletions src/easylog/tests/test_easylog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ TEST_CASE("test basic") {
CHECK(get_last_line(filename).rfind("rpc header data_len: 42, buf sz: 20") !=
std::string::npos);

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

ELOG(INFO) << "test log";
easylog::flush();
CHECK(get_last_line(filename).rfind("test log") != std::string::npos);
Expand Down
Loading