diff --git a/frameworks/mini/hiview_output_log.c b/frameworks/mini/hiview_output_log.c index cbaf8633afe4f51f1d915cb91e050013cd3e9970..c666a985a7a6721708cf99a635c8c35a0c712dd5 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.");