From a04d1a44441a6d19f105177c0a6c9b73d36291ec Mon Sep 17 00:00:00 2001
From: xietangxin <xietangxin@huawei.com>
Date: Mon, 29 Apr 2024 19:25:01 +0800
Subject: [PATCH] fix writing metadata to log file properly

---
 doc/constraints_introduction.md | 4 ++--
 src/common/logs.c               | 7 +++----
 src/lib/meta/meta.c             | 8 ++++++--
 3 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/doc/constraints_introduction.md b/doc/constraints_introduction.md
index 4e25a1f..8a30224 100644
--- a/doc/constraints_introduction.md
+++ b/doc/constraints_introduction.md
@@ -38,5 +38,5 @@ logs =
     ...
 };
 ```
-#### 1.2.3 meta 与 raw 日志  
-- meta， raw 日志打印配置与 debug 基本相同， 备份与最大校验尺寸配置方法一致。
+#### 1.2.3 meta 日志
+- meta 日志当前允许最大存储量为 100MB， 单位 MB, 当前meta日志不允许备份，当超过最大允许存储后会清除后重头部开始写
diff --git a/src/common/logs.c b/src/common/logs.c
index 7a2ba16..b68e1c8 100644
--- a/src/common/logs.c
+++ b/src/common/logs.c
@@ -363,7 +363,7 @@ static void init_all_logger(void)
     init_logger(&g_metrics_logger, "metrics", 0, METRICS_LOGS_FILESIZE);
     init_logger(&g_event_logger, "event", 1, EVENT_LOGS_FILESIZE);
     init_logger(&g_debug_logger, "debug", 1, DEBUG_LOGS_FILESIZE);
-    init_logger(&g_meta_logger, "meta", 1, META_LOGS_FILESIZE);
+    init_logger(&g_meta_logger, "meta", 0, META_LOGS_FILESIZE);
 }
 
 #define FULL_PATH_LEN (PATH_LEN * 2)
@@ -777,9 +777,8 @@ void wr_meta_logs(const char* logs)
     if (access(g_meta_abs_path, F_OK) == -1) {
         (void)append_meta_logger(local);
     }
-    if (g_meta_logger.level <= LOGGER_DEBUG) {  // using debug level
-        log_without_date(&g_meta_logger, logs);
-    }
+
+    log_without_date(&g_meta_logger, logs);
 }
 
 static void reappend_debug_logger(struct log_mgr_s *mgr)
diff --git a/src/lib/meta/meta.c b/src/lib/meta/meta.c
index 156b1cd..9302363 100644
--- a/src/lib/meta/meta.c
+++ b/src/lib/meta/meta.c
@@ -591,6 +591,10 @@ static int report_one_metadata(const MeasurementMgr *mgr, const Measurement *mm)
     int ret;
     char *json_str = NULL;
 
+    if (mgr->meta_out_channel != OUT_CHNL_KAFKA && mgr->meta_out_channel != OUT_CHNL_LOGS) {
+        return 0;
+    }
+
     json_str = (char *)malloc(MAX_DATA_STR_LEN);
     if (json_str == NULL) {
         return -1;
@@ -628,7 +632,7 @@ static int report_one_metadata(const MeasurementMgr *mgr, const Measurement *mm)
     return 0;
 }
 
-static int ReportMeteData(const MeasurementMgr *mgr)
+static int ReportMetaData(const MeasurementMgr *mgr)
 {
     Measurement *mm = NULL;
     int i, meta_num;
@@ -670,7 +674,7 @@ int ReportMetaDataMain(const MeasurementMgr *mgr)
 #endif
 
     for (;;) {
-        ret = ReportMeteData(mgr);
+        ret = ReportMetaData(mgr);
         if (ret < 0) {
             return -1;
         }
-- 
2.28.0.windows.1

