fix crash on ULIB_LOG_LEVEL=alpha
Some checks failed
rpcrypto-build / build (Release, himix200.toolchain.cmake) (push) Failing after 1m9s
linux-mips64-gcc / linux-gcc-mips64el (push) Failing after 56s
linux-x64-gcc / linux-gcc (push) Failing after 53s
rpcrypto-build / build (Debug, mipsel-openwrt-linux-musl.toolchain.cmake) (push) Failing after 1m18s
rpcrypto-build / build (Release, mipsel-openwrt-linux.toolchain.cmake) (push) Failing after 1m17s
rpcrypto-build / build (Release, hisiv510.toolchain.cmake) (push) Failing after 1m27s
rpcrypto-build / build (Debug, himix200.toolchain.cmake) (push) Has been cancelled
rpcrypto-build / build (Debug, hisiv510.toolchain.cmake) (push) Has been cancelled
rpcrypto-build / build (Debug, mipsel-openwrt-linux.toolchain.cmake) (push) Has been cancelled
rpcrypto-build / build (Release, mipsel-openwrt-linux-musl.toolchain.cmake) (push) Has been cancelled
linux-hisiv500-gcc / linux-gcc-hisiv500 (push) Has been cancelled

This commit is contained in:
tqcq 2023-12-11 16:51:17 +08:00
parent bf5e765acf
commit 0d6f84c832

View File

@ -23,10 +23,18 @@ Logger::GetInstance()
Logger::Logger() {
const char* env_level = getenv("ULIB_LOG_LEVEL");
printf("ULIB_LOG_LEVEL: %s\n", env_level);
if (!env_level) {
SetLogLevel(Level::kALL);
} else {
char buffer[1024] = "invalid ULIB_LOG_LEVEL=";
for (const char* ptr = env_level; ptr && *ptr; ++ptr) {
if (!isnumber(*ptr)) {
strncat(buffer + strlen(buffer), env_level, 1000);
Log(Level::kError, "logger.cpp", __FUNCTION__, __LINE__, "ulib.log", buffer);
return;
}
}
int level = atoi(env_level);
level = std::max(static_cast<int>(Level::kALL), std::min(static_cast<int>(Level::kOFF), level));
SetLogLevel(static_cast<Level::LevelEnum>(level));