From d3264d38cc5b2046e2e6af1035c8266f7426e345 Mon Sep 17 00:00:00 2001 From: xue_meng_en <1836611252@qq.com> Date: Thu, 16 Mar 2023 20:44:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=97=A5=E5=BF=97=E5=8E=8B?= =?UTF-8?q?=E7=BC=A9=E7=BA=BF=E7=A8=8B=E6=97=A5=E5=BF=97=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E4=B8=8D=E5=87=86=E7=A1=AE=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cm_agent/cma_log_management.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/cm_agent/cma_log_management.cpp b/src/cm_agent/cma_log_management.cpp index 572eb9b..12bbdb8 100644 --- a/src/cm_agent/cma_log_management.cpp +++ b/src/cm_agent/cma_log_management.cpp @@ -255,7 +255,7 @@ int GZCompress(char *inpath, uint32 inLen, char *outpath, uint32 outLen) * This function can process different data node but have same pattern */ void groupByDirectoryAndPattern(LogFile* logFile, LogFile* sortLogFile, const char* pattern, const char* basePath, - uint32 count) + uint32 count, uint32 &numCompressed) { errno_t rc; char outpath[MAX_PATH_LEN] = {'\0'}; @@ -283,6 +283,8 @@ void groupByDirectoryAndPattern(LogFile* logFile, LogFile* sortLogFile, const ch rc = snprintf_s(outpath, MAX_PATH_LEN, MAX_PATH_LEN - 1, "%s%s", sortLogFile[jj].fileName, ".gz"); securec_check_intval(rc, (void)rc); if (GZCompress(sortLogFile[jj].fileName, MAX_PATH_LEN, outpath, MAX_PATH_LEN) == 0) { + write_runlog(LOG, "Compressed log file, file name: %s\n", sortLogFile[jj].fileName); + ++numCompressed; /* Compress successful then remove the source trace, and chmod */ (void)chmod(outpath, S_IRUSR); delLogFile(sortLogFile[jj].fileName); @@ -379,6 +381,7 @@ static void gzCompressLogFile(const char *pattern) } /* Find traces of one directory */ + uint32 numCompressed = 0; for (uint32 jj = 0; jj < count; jj++) { if (strcmp(logFile[jj].pattern, pattern) == 0 && strstr(logFile[jj].fileName, ".gz") == NULL) { /* Skip directory that be processed */ @@ -388,14 +391,16 @@ static void gzCompressLogFile(const char *pattern) basePath = logFile[jj].basePath; allBasePath[cnt] = logFile[jj].basePath; - groupByDirectoryAndPattern(logFile, sortLogFile, pattern, basePath, count); + groupByDirectoryAndPattern(logFile, sortLogFile, pattern, basePath, count, numCompressed); /* Clear sort log buffer for next directory sort */ rc = memset_s(sortLogFile, sizeof(LogFile) * totalCount, 0, sizeof(LogFile) * totalCount); securec_check_errno(rc, (void)rc); cnt++; } } - write_runlog(LOG, "Compress log directory.Directory Name=%s,File Count=%u\n", pattern, cnt); + if (numCompressed != 0) { + write_runlog(LOG, "Compressed log directory, pattern name=%s, file count=%u\n", pattern, numCompressed); + } FREE_AND_RESET(sortLogFile); FREE_AND_RESET(logFile); FREE_AND_RESET(allBasePath);