diff --git a/include/util/tlog.h b/include/util/tlog.h index 451c2bb819..9827331258 100644 --- a/include/util/tlog.h +++ b/include/util/tlog.h @@ -71,8 +71,8 @@ extern int32_t sndDebugFlag; extern int32_t simDebugFlag; extern int32_t tqClientDebugFlag; - int32_t taosInitLogOutput(const char **ppLogName); +int32_t taosSetLogOutput(); int32_t taosInitLog(const char *logName, int32_t maxFiles, bool tsc); void taosCloseLog(); void taosResetLog(); diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 1507cbf14d..20b3056af9 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -1019,29 +1019,7 @@ static int32_t taosSetClientLogCfg(SConfig *pCfg) { TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "logDir"); tstrncpy(tsLogDir, pItem->str, PATH_MAX); TAOS_CHECK_RETURN(taosExpandDir(tsLogDir, tsLogDir, PATH_MAX)); - - if (tsLogOutput) { - char *pLog = tsLogOutput; - if (strcasecmp(pLog, "stdout") && strcasecmp(pLog, "stderr") && strcasecmp(pLog, "/dev/null")) { - char *pEnd = NULL; - if ((pEnd = strrchr(pLog, '/')) || (pEnd = strrchr(pLog, '\\'))) { - int32_t pathLen = POINTER_DISTANCE(pEnd, pLog) + 1; - if (*pLog == '/' || *pLog == '\\') { - if (pathLen >= PATH_MAX) TAOS_RETURN(TSDB_CODE_OUT_OF_RANGE); - tstrncpy(tsLogDir, pLog, pathLen); - } else { - int32_t len = strlen(tsLogDir); - if (tsLogDir[len - 1] != '/' && tsLogDir[len - 1] != '\\') { - tsLogDir[len++] = TD_DIRSEP_CHAR; - } - int32_t remain = PATH_MAX - len - 1; - if (remain < pathLen) TAOS_RETURN(TSDB_CODE_OUT_OF_RANGE); - tstrncpy(tsLogDir + len, pLog, pathLen); - } - TAOS_CHECK_RETURN(cfgSetItem(pCfg, "logDir", tsLogDir, CFG_STYPE_DEFAULT, true)); - } - } - } + TAOS_CHECK_RETURN(taosSetLogOutput(pCfg)); TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "minimalLogDirGB"); tsLogSpace.reserved = (int64_t)(((double)pItem->fval) * 1024 * 1024 * 1024); @@ -1871,7 +1849,6 @@ int32_t taosInitCfg(const char *cfgDir, const char **envCmd, const char *envFile TAOS_CHECK_GOTO(taosAddSystemCfg(tsCfg), &lino, _exit); -#if 0 // duplicate operation since already loaded in taosCreateLog if ((code = taosLoadCfg(tsCfg, envCmd, cfgDir, envFile, apolloUrl)) != 0) { (void)printf("failed to load cfg since %s\n", tstrerror(code)); cfgCleanup(tsCfg); @@ -1885,11 +1862,12 @@ int32_t taosInitCfg(const char *cfgDir, const char **envCmd, const char *envFile tsCfg = NULL; TAOS_RETURN(code); } -#endif if (tsc) { + TAOS_CHECK_GOTO(taosSetClientLogCfg(tsCfg), &lino, _exit); TAOS_CHECK_GOTO(taosSetClientCfg(tsCfg), &lino, _exit); } else { + TAOS_CHECK_GOTO(taosSetClientLogCfg(tsCfg), &lino, _exit); TAOS_CHECK_GOTO(taosSetClientCfg(tsCfg), &lino, _exit); TAOS_CHECK_GOTO(taosUpdateServerCfg(tsCfg), &lino, _exit); TAOS_CHECK_GOTO(taosSetServerCfg(tsCfg), &lino, _exit); diff --git a/source/util/src/tlog.c b/source/util/src/tlog.c index b441641c94..09835d7978 100644 --- a/source/util/src/tlog.c +++ b/source/util/src/tlog.c @@ -297,6 +297,30 @@ int32_t taosInitLogOutput(const char **ppLogName) { return 0; } +int32_t taosSetLogOutput(SConfig *pCfg) { + if (tsLogOutput && (tsLogObj.outputType == LOG_OUTPUT_FILE)) { + char *pLog = tsLogOutput; + char *pEnd = NULL; + if ((pEnd = strrchr(pLog, '/')) || (pEnd = strrchr(pLog, '\\'))) { + int32_t pathLen = POINTER_DISTANCE(pEnd, pLog) + 1; + if (*pLog == '/' || *pLog == '\\') { + if (pathLen >= PATH_MAX) TAOS_RETURN(TSDB_CODE_OUT_OF_RANGE); + tstrncpy(tsLogDir, pLog, pathLen); + } else { + int32_t len = strlen(tsLogDir); + if (tsLogDir[len - 1] != '/' && tsLogDir[len - 1] != '\\') { + tsLogDir[len++] = TD_DIRSEP_CHAR; + } + int32_t remain = PATH_MAX - len - 1; + if (remain < pathLen) TAOS_RETURN(TSDB_CODE_OUT_OF_RANGE); + tstrncpy(tsLogDir + len, pLog, pathLen); + } + TAOS_CHECK_RETURN(cfgSetItem(pCfg, "logDir", tsLogDir, CFG_STYPE_DEFAULT, true)); + } + } + return 0; +} + int32_t taosInitLog(const char *logName, int32_t maxFiles, bool tsc) { if (atomic_val_compare_exchange_8(&tsLogInited, 0, 1) != 0) return 0; int32_t code = osUpdate();