From 43c64db722573a7cbff2f6b58e8ca610ed5e7ff2 Mon Sep 17 00:00:00 2001 From: shenchenkai Date: Sat, 18 Dec 2021 16:26:06 +0800 Subject: [PATCH] Description:[feature] enhance recoverability Change-Id: I9eb61010398475e3f53c2964f6c833c17fae06fa Signed-off-by: shenchenkai --- frameworks/mini/hiview_output_log.c | 30 +++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/frameworks/mini/hiview_output_log.c b/frameworks/mini/hiview_output_log.c index cbaf863..30274db 100755 --- a/frameworks/mini/hiview_output_log.c +++ b/frameworks/mini/hiview_output_log.c @@ -68,6 +68,9 @@ struct OutputLogInfo { }; static OutputLogInfo g_outputLogInfo; +static int32 g_retryInitCount = 0; +#define MAX_RETRY_COUNT 100 + /* Output the log to UART using plaintext. */ static void OutputLogRealtime(const Request *req); /* Output the log to FLASH using text. */ @@ -257,6 +260,15 @@ static void OutputLog2TextFile(const Request *req) // prevent writing '\0' character to file len--; } + if (g_logFile.fhandle < 0) { + if (g_retryInitCount < MAX_RETRY_COUNT) { + InitLogOutput(); + } + g_retryInitCount++; + } else { + // once success, clean retry count + g_retryInitCount = 0; + } if (len > 0 && WriteToFile(&g_logFile, (uint8 *)tempOutStr, len) != len) { g_hiviewConfig.writeFailureCount++; } @@ -298,12 +310,26 @@ static void OutputLog2BinFile(const Request *req) } valueLen = pCommonContent->valueNumber * sizeof(uint32); if (valueLen > 0) { + if ((int32)len + (int32)valueLen > (int32)outputSize) { + DiscardCacheData(&g_logCache); + HIVIEW_UartPrint("Discard cache[LOG_CACHE] data."); + break; + } if (ReadFromCache(&g_logCache, tmpBuffer + len, valueLen) != valueLen) { continue; } len += valueLen; } } + if (g_logFile.fhandle < 0) { + if (g_retryInitCount < MAX_RETRY_COUNT) { + InitLogOutput(); + } + g_retryInitCount++; + } else { + // once success, clean retry count + g_retryInitCount = 0; + } if (len > 0 && WriteToFile(&g_logFile, tmpBuffer, len) != len) { g_hiviewConfig.writeFailureCount++; HIVIEW_UartPrint("Failed to write log data."); @@ -384,7 +410,7 @@ static int32 LogCommonFmt(char *outStr, int32 outStrLen, const HiLogCommon *comm min = nowTime.tm_min; sec = nowTime.tm_sec; level = CLEAR_HASH_FLAG(commonContentPtr->level); - if (level < 0 || level >= HILOG_LV_MAX) { + if (level >= HILOG_LV_MAX) { level = 0; } ret = snprintf_s(outStr, outStrLen, outStrLen - 1, "%02d-%02d %02d:%02d:%02d.%03d 0 %d %c %d/%s: ", @@ -573,7 +599,7 @@ void HiviewUnRegisterHilogProc(HilogProc func) void HiviewRegisterHiLogFileWatcher(FileProc func, const char *path) { - if (func == NULL || path == NULL) { + if (func == NULL) { return; } RegisterFileWatcher(&g_logFile, func, path); -- Gitee