From f6b9cc5aeebec19c5517195ead74fff942f95b7e Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Thu, 7 Mar 2024 14:30:47 +0800 Subject: [PATCH] feat support log level --- include/sled/log/log.h | 1 + src/log/log.cc | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/include/sled/log/log.h b/include/sled/log/log.h index 82108a4..08e50ab 100644 --- a/include/sled/log/log.h +++ b/include/sled/log/log.h @@ -20,6 +20,7 @@ enum class LogLevel { kError, kFatal, }; +void SetLogLevel(LogLevel level); void Log(LogLevel level, const char *tag, diff --git a/src/log/log.cc b/src/log/log.cc index f5cbddc..6cf4b85 100644 --- a/src/log/log.cc +++ b/src/log/log.cc @@ -97,6 +97,14 @@ GetCurrentUTCTime() return result; } +static LogLevel g_log_level = LogLevel::kTrace; + +void +SetLogLevel(LogLevel level) +{ + g_log_level = level; +} + void Log(LogLevel level, const char *tag, @@ -106,6 +114,8 @@ Log(LogLevel level, const char *func_name, ...) { + if (level < g_log_level) { return; } + static std::atomic_bool allow(true); ScopedAtomicWaiter waiter(allow); int len = file_name ? strlen(file_name) : 0;