From bf5e765acfcab193e849bae0194a94870bfe5ca7 Mon Sep 17 00:00:00 2001 From: tqcq Date: Mon, 11 Dec 2023 16:44:42 +0800 Subject: [PATCH] feature support log control --- src/ulib/log/logger.cpp | 10 ++++++++-- src/ulib/log/logger.h | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/ulib/log/logger.cpp b/src/ulib/log/logger.cpp index 4f46451..ed1bf84 100644 --- a/src/ulib/log/logger.cpp +++ b/src/ulib/log/logger.cpp @@ -25,11 +25,11 @@ Logger::Logger() { const char* env_level = getenv("ULIB_LOG_LEVEL"); printf("ULIB_LOG_LEVEL: %s\n", env_level); if (!env_level) { - level_ = Level::kALL; + SetLogLevel(Level::kALL); } else { int level = atoi(env_level); level = std::max(static_cast(Level::kALL), std::min(static_cast(Level::kOFF), level)); - level_ = static_cast(level); + SetLogLevel(static_cast(level)); } } @@ -71,4 +71,10 @@ Logger::SetStrippedPrefixLen(size_t len) stripped_prefix_len_ = len; } +void +Logger::SetLogLevel(Level::LevelEnum min_level) +{ + level_ = min_level; +} + }// namespace tqcq diff --git a/src/ulib/log/logger.h b/src/ulib/log/logger.h index 9166df0..01af1a4 100644 --- a/src/ulib/log/logger.h +++ b/src/ulib/log/logger.h @@ -16,6 +16,7 @@ public: Logger(); ~Logger(); static Logger &GetInstance(); + void SetLogLevel(Level::LevelEnum min_level); void Log(int32_t level, const char *file, const char *func, int32_t line, const char* tag,const char *msg); void SetStrippedPrefixLen(size_t len);