From 35f83bd70abd3e35a93073117089e34d8eff90b6 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Fri, 30 Aug 2024 10:04:01 +0800 Subject: [PATCH] fix:[TD-31696]print error log to screen if init error --- source/common/src/tglobal.c | 18 +++++++++--------- source/util/src/tconfig.c | 30 ++++++++++++++++-------------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 4d486518ee..f44c0b0b51 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -485,27 +485,27 @@ static int32_t taosLoadCfg(SConfig *pCfg, const char **envCmd, const char *input } if ((code = cfgLoad(pCfg, CFG_STYPE_APOLLO_URL, apolloUrl)) != 0) { - uError("failed to load from apollo url:%s since %s", apolloUrl, tstrerror(code)); + printf("failed to load from apollo url:%s since %s\n", apolloUrl, tstrerror(code)); TAOS_RETURN(code); } if ((code = cfgLoad(pCfg, CFG_STYPE_CFG_FILE, cfgFile)) != 0) { - uError("failed to load from cfg file:%s since %s", cfgFile, tstrerror(code)); + printf("failed to load from cfg file:%s since %s\n", cfgFile, tstrerror(code)); TAOS_RETURN(code); } if ((code = cfgLoad(pCfg, CFG_STYPE_ENV_FILE, envFile)) != 0) { - uError("failed to load from env file:%s since %s", envFile, tstrerror(code)); + printf("failed to load from env file:%s since %s\n", envFile, tstrerror(code)); TAOS_RETURN(code); } if ((code = cfgLoad(pCfg, CFG_STYPE_ENV_VAR, NULL)) != 0) { - uError("failed to load from global env variables since %s", tstrerror(code)); + printf("failed to load from global env variables since %s\n", tstrerror(code)); TAOS_RETURN(code); } if ((code = cfgLoad(pCfg, CFG_STYPE_ENV_CMD, envCmd)) != 0) { - uError("failed to load from cmd env variables since %s", tstrerror(code)); + printf("failed to load from cmd env variables since %s\n", tstrerror(code)); TAOS_RETURN(code); } @@ -1769,14 +1769,14 @@ int32_t taosInitCfg(const char *cfgDir, const char **envCmd, const char *envFile TAOS_CHECK_GOTO(taosAddSystemCfg(tsCfg), &lino, _exit); if ((code = taosLoadCfg(tsCfg, envCmd, cfgDir, envFile, apolloUrl)) != 0) { - uError("failed to load cfg since %s", tstrerror(code)); + printf("failed to load cfg since %s\n", tstrerror(code)); cfgCleanup(tsCfg); tsCfg = NULL; TAOS_RETURN(code); } if ((code = cfgLoadFromArray(tsCfg, pArgs)) != 0) { - uError("failed to load cfg from array since %s", tstrerror(code)); + printf("failed to load cfg from array since %s\n", tstrerror(code)); cfgCleanup(tsCfg); tsCfg = NULL; TAOS_RETURN(code); @@ -1798,7 +1798,7 @@ int32_t taosInitCfg(const char *cfgDir, const char **envCmd, const char *envFile SConfigItem *pItem = cfgGetItem(tsCfg, "debugFlag"); if (NULL == pItem) { - uError("debugFlag not found in cfg"); + printf("debugFlag not found in cfg\n"); TAOS_RETURN(TSDB_CODE_CFG_NOT_FOUND); } TAOS_CHECK_GOTO(taosSetAllDebugFlag(tsCfg, pItem->i32), &lino, _exit); @@ -1811,7 +1811,7 @@ _exit: if (TSDB_CODE_SUCCESS != code) { cfgCleanup(tsCfg); tsCfg = NULL; - uError("failed to init cfg at %d since %s", lino, tstrerror(code)); + printf("failed to init cfg at %d since %s\n", lino, tstrerror(code)); } TAOS_RETURN(code); diff --git a/source/util/src/tconfig.c b/source/util/src/tconfig.c index a20000b9ee..0ff2cf4eae 100644 --- a/source/util/src/tconfig.c +++ b/source/util/src/tconfig.c @@ -383,10 +383,6 @@ int32_t cfgSetItem(SConfig *pCfg, const char *name, const char *value, ECfgSrcTy (void)taosThreadMutexUnlock(&pCfg->lock); } - if (code != 0){ - printf("cfg:%s, type:%s src:%s value:%s failed since %s\n", pItem->name, cfgDtypeStr(pItem->dtype), - cfgStypeStr(stype), value, tstrerror(code)); - } TAOS_RETURN(code); } @@ -998,7 +994,7 @@ int32_t cfgLoadFromEnvFile(SConfig *pConfig, const char *envFile) { const char *filepath = ".env"; if (envFile != NULL && strlen(envFile) > 0) { if (!taosCheckExistFile(envFile)) { - uError("failed to load env file:%s", envFile); + printf("failed to load env file:%s\n", envFile); TAOS_RETURN(TSDB_CODE_NOT_FOUND); } filepath = envFile; @@ -1073,7 +1069,7 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) { uInfo("failed to load from cfg file %s since %s, use default parameters", filepath, tstrerror(code)); TAOS_RETURN(TSDB_CODE_SUCCESS); } else { - uError("failed to load from cfg file %s since %s", filepath, tstrerror(code)); + printf("failed to load from cfg file %s since %s\n", filepath, tstrerror(code)); TAOS_RETURN(code); } } @@ -1115,6 +1111,9 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) { } code = cfgSetItem(pConfig, name, newValue, CFG_STYPE_CFG_FILE, true); + if (code != 0){ + printf("cfg:%s, value:%s failed since %s\n", name,newValue, tstrerror(code)); + } if (TSDB_CODE_SUCCESS != code && TSDB_CODE_CFG_NOT_FOUND != code) break; } else { (void)paGetToken(value + vlen + 1, &value2, &vlen2); @@ -1129,6 +1128,9 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) { } code = cfgSetItem(pConfig, name, value, CFG_STYPE_CFG_FILE, true); + if (code != 0){ + printf("cfg:%s, value:%s failed since %s\n", name, value, tstrerror(code)); + } if (TSDB_CODE_SUCCESS != code && TSDB_CODE_CFG_NOT_FOUND != code) break; } @@ -1152,7 +1154,7 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) { uInfo("load from cfg file %s success", filepath); TAOS_RETURN(TSDB_CODE_SUCCESS); } else { - uError("failed to load from cfg file %s since %s", filepath, tstrerror(code)); + printf("failed to load from cfg file %s since %s\n", filepath, tstrerror(code)); TAOS_RETURN(code); } } @@ -1234,7 +1236,7 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) { char *p = strchr(url, ':'); if (p == NULL) { - uError("fail to load apoll url: %s, unknown format", url); + printf("fail to load apoll url: %s, unknown format\n", url); TAOS_RETURN(TSDB_CODE_INVALID_PARA); } p++; @@ -1242,7 +1244,7 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) { if (strncmp(url, "jsonFile", 8) == 0) { char *filepath = p; if (!taosCheckExistFile(filepath)) { - uError("failed to load json file:%s", filepath); + printf("failed to load json file:%s\n", filepath); TAOS_RETURN(TSDB_CODE_NOT_FOUND); } @@ -1254,7 +1256,7 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) { char *buf = taosMemoryMalloc(fileSize + 1); if (!buf) { (void)taosCloseFile(&pFile); - uError("load json file error: %s, failed to alloc memory", filepath); + printf("load json file error: %s, failed to alloc memory\n", filepath); TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); } @@ -1262,7 +1264,7 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) { (void)taosLSeekFile(pFile, 0, SEEK_SET); if (taosReadFile(pFile, buf, fileSize) <= 0) { (void)taosCloseFile(&pFile); - uError("load json file error: %s", filepath); + printf("load json file error: %s\n", filepath); taosMemoryFreeClear(buf); TAOS_RETURN(TSDB_CODE_INVALID_DATA_FMT); } @@ -1271,7 +1273,7 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) { if (NULL == pJson) { const char *jsonParseError = tjsonGetError(); if (jsonParseError != NULL) { - uError("load json file parse error: %s", jsonParseError); + printf("load json file parse error: %s\n", jsonParseError); } taosMemoryFreeClear(buf); TAOS_CHECK_EXIT(TSDB_CODE_INVALID_DATA_FMT); @@ -1339,7 +1341,7 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) { // } else if (strncmp(url, "jsonUrl", 7) == 0) { // } else if (strncmp(url, "etcdUrl", 7) == 0) { } else { - uError("Unsupported url: %s", url); + printf("Unsupported url: %s\n", url); TAOS_RETURN(TSDB_CODE_INVALID_PARA); } @@ -1351,7 +1353,7 @@ _exit: taosMemoryFree(cfgLineBuf); tjsonDelete(pJson); if (code != 0) { - uError("failed to load from apollo url:%s at line %d since %s", url, lino, tstrerror(code)); + printf("failed to load from apollo url:%s at line %d since %s\n", url, lino, tstrerror(code)); } TAOS_RETURN(code); }