提交 bed68741 编写于 作者: S Shengliang Guan

enh: add tassert

上级 dbb90c21
......@@ -38,6 +38,7 @@ typedef void (*LogFp)(int64_t ts, ELogLevel level, const char *content);
extern bool tsLogEmbedded;
extern bool tsAsyncLog;
extern bool tsAssert;
extern int32_t tsNumOfLogLines;
extern int32_t tsLogKeepDays;
extern LogFp tsLogFp;
......@@ -82,6 +83,10 @@ void taosPrintLongString(const char *flags, ELogLevel level, int32_t dflag, cons
#endif
;
bool taosAssertLog(bool condition, const char *file, int32_t line, const char *format, ...);
#define tAssert(...) (void)taosAssertLog(condition, __FILE__, __LINE__, __VA_ARGS__);
#define tAssertR(...) taosAssertLog(condition, __FILE__, __LINE__, __VA_ARGS__)
// clang-format off
#define uFatal(...) { if (uDebugFlag & DEBUG_FATAL) { taosPrintLog("UTL FATAL", DEBUG_FATAL, tsLogEmbedded ? 255 : uDebugFlag, __VA_ARGS__); }}
#define uError(...) { if (uDebugFlag & DEBUG_ERROR) { taosPrintLog("UTL ERROR ", DEBUG_ERROR, tsLogEmbedded ? 255 : uDebugFlag, __VA_ARGS__); }}
......
......@@ -334,6 +334,7 @@ static int32_t taosAddSystemCfg(SConfig *pCfg) {
if (cfgAddLocale(pCfg, "locale", tsLocale) != 0) return -1;
if (cfgAddCharset(pCfg, "charset", tsCharset) != 0) return -1;
if (cfgAddBool(pCfg, "enableCoreFile", 1, 1) != 0) return -1;
if (cfgAddBool(pCfg, "assert", 1, 1) != 0) return -1;
if (cfgAddFloat(pCfg, "numOfCores", tsNumOfCores, 1, 100000, 1) != 0) return -1;
if (cfgAddBool(pCfg, "SSE42", tsSSE42Enable, 0) != 0) return -1;
......@@ -693,6 +694,8 @@ static void taosSetSystemCfg(SConfig *pCfg) {
bool enableCore = cfgGetItem(pCfg, "enableCoreFile")->bval;
taosSetCoreDump(enableCore);
tsAssert = cfgGetItem(pCfg, "assert")->bval;
// todo
tsVersion = 30000000;
}
......@@ -788,7 +791,9 @@ int32_t taosSetCfg(SConfig *pCfg, char *name) {
case 'a': {
if (strcasecmp("asyncLog", name) == 0) {
tsAsyncLog = cfgGetItem(pCfg, "asyncLog")->bval;
}
} else if (strcasecmp("assert", name) == 0) {
tsAssert = cfgGetItem(pCfg, "assert")->bval;
}
break;
}
case 'c': {
......
......@@ -72,6 +72,7 @@ static int32_t tsDaylightActive; /* Currently in daylight saving time. */
bool tsLogEmbedded = 0;
bool tsAsyncLog = true;
bool tsAssert = true;
int32_t tsNumOfLogLines = 10000000;
int32_t tsLogKeepDays = 0;
LogFp tsLogFp = NULL;
......@@ -778,3 +779,32 @@ cmp_end:
return ret;
}
bool taosAssertLog(bool condition, const char *file, int32_t line, const char *format, ...) {
if (!condition) return false;
char buffer[LOG_MAX_LINE_BUFFER_SIZE];
int32_t len = taosBuildLogHead(buffer, "UTL FATAL");
va_list argpointer;
va_start(argpointer, format);
int32_t writeLen = len + vsnprintf(buffer + len, LOG_MAX_LINE_BUFFER_SIZE - len, format, argpointer);
va_end(argpointer);
char fullBuf[LOG_MAX_LINE_BUFFER_SIZE];
int32_t fullLen = snprintf(fullBuf, sizeof(fullBuf), "ASSERT at file:%s:%d, %s", file, line, buffer);
taosPrintLogImp(1, 255, fullBuf, fullLen);
if (tsAssert) {
taosCloseLog();
taosMsleep(300);
#if NDEBUG
abort();
#else
ASSERT(1);
#endif
}
return true;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册