From 9e2f22fcb983433ec689e66ee40dd6ef189a2d90 Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Thu, 28 Dec 2023 15:51:28 +0800 Subject: [PATCH] feat use short log level --- src/ulib/log/level.h | 20 ++++++++++++++++++++ src/ulib/log/logger.cpp | 4 ++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/ulib/log/level.h b/src/ulib/log/level.h index 5c0c355..6c9ae0e 100644 --- a/src/ulib/log/level.h +++ b/src/ulib/log/level.h @@ -42,6 +42,26 @@ public: FATAL = ULOG_LEVEL_FATAL }; + static const char *ToShortString(int level) + { + switch (level) { + case kTrace: + return "T"; + case kDebug: + return "D"; + case kInfo: + return "I"; + case kWarn: + return "W"; + case kError: + return "E"; + case kFatal: + return "F"; + default: + return "UNKNOWN"; + } + } + static const char *ToString(int level) { switch (level) { diff --git a/src/ulib/log/logger.cpp b/src/ulib/log/logger.cpp index a5531f1..d87aa2f 100644 --- a/src/ulib/log/logger.cpp +++ b/src/ulib/log/logger.cpp @@ -53,7 +53,7 @@ Logger::Log(int32_t level, const char *msg) { if (level < level_) { return; } - const char *level_name = Level::ToString(level); + const char *level_name = Level::ToShortString(level); /** * @brief time file:line@func tag level_name msg */ @@ -62,7 +62,7 @@ Logger::Log(int32_t level, /** * @brief time level_name tag file:line@func msg */ - std::string pattern = "{} [{}] {} {}:{}@{}: {}"; + std::string pattern = "{} {} {} {}:{}@{}: {}"; std::string log_time; { std::time_t now = time(NULL);