feature support log control

This commit is contained in:
tqcq 2023-12-11 16:44:42 +08:00
parent db23cfa645
commit bf5e765acf
2 changed files with 9 additions and 2 deletions

View File

@ -25,11 +25,11 @@ Logger::Logger() {
const char* env_level = getenv("ULIB_LOG_LEVEL"); const char* env_level = getenv("ULIB_LOG_LEVEL");
printf("ULIB_LOG_LEVEL: %s\n", env_level); printf("ULIB_LOG_LEVEL: %s\n", env_level);
if (!env_level) { if (!env_level) {
level_ = Level::kALL; SetLogLevel(Level::kALL);
} else { } else {
int level = atoi(env_level); int level = atoi(env_level);
level = std::max(static_cast<int>(Level::kALL), std::min(static_cast<int>(Level::kOFF), level)); level = std::max(static_cast<int>(Level::kALL), std::min(static_cast<int>(Level::kOFF), level));
level_ = static_cast<Level::LevelEnum>(level); SetLogLevel(static_cast<Level::LevelEnum>(level));
} }
} }
@ -71,4 +71,10 @@ Logger::SetStrippedPrefixLen(size_t len)
stripped_prefix_len_ = len; stripped_prefix_len_ = len;
} }
void
Logger::SetLogLevel(Level::LevelEnum min_level)
{
level_ = min_level;
}
}// namespace tqcq }// namespace tqcq

View File

@ -16,6 +16,7 @@ public:
Logger(); Logger();
~Logger(); ~Logger();
static Logger &GetInstance(); 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 Log(int32_t level, const char *file, const char *func, int32_t line, const char* tag,const char *msg);
void SetStrippedPrefixLen(size_t len); void SetStrippedPrefixLen(size_t len);