From 4c86ef5908d10a9d6c29c80d39c993fbce0ab99c Mon Sep 17 00:00:00 2001
From: licunlong <licunlong1@huawei.com>
Date: Sun, 25 Jun 2023 14:54:03 +0800
Subject: [PATCH] feature: add LogFileSize and LogFileNumber

---
 core/bin/main.rs           |  9 +++------
 core/bin/manager/config.rs |  6 ++++++
 core/bin/unit/manager.rs   | 16 ++++++++++++++++
 core/lib/unit/umif.rs      | 10 ++++++++++
 5 files changed, 59 insertions(+), 8 deletions(-)

diff --git a/core/bin/main.rs b/core/bin/main.rs
index 7f163c7..b75ef0b 100644
--- a/core/bin/main.rs
+++ b/core/bin/main.rs
@@ -82,16 +82,13 @@ fn main() -> Result<()> {
     let args = Args::parse();
 
     let manager_config = Rc::new(ManagerConfig::new(None));
-    let log_file = if manager_config.LogFile.is_empty() {
-        None
-    } else {
-        Some(manager_config.LogFile.as_str())
-    };
     logger::init_log(
         "sysmaster",
         manager_config.LogLevel,
         &manager_config.LogTarget,
-        log_file,
+        &manager_config.LogFile,
+        manager_config.LogFileSize,
+        manager_config.LogFileNumber,
     );
     log::info!("sysmaster running in system mode.");
 
diff --git a/core/bin/manager/config.rs b/core/bin/manager/config.rs
index 8b7aaab..fc4c028 100644
--- a/core/bin/manager/config.rs
+++ b/core/bin/manager/config.rs
@@ -30,6 +30,10 @@ pub struct ManagerConfig {
     pub LogTarget: String,
     #[config(default = "")]
     pub LogFile: String,
+    #[config(default = 10240)]
+    pub LogFileSize: u32,
+    #[config(default = 10)]
+    pub LogFileNumber: u32,
 
     #[config(default = 1048576)] // RELI_HISTORY_MAPSIZE_DEFAULT
     pub DbSize: usize,
@@ -55,6 +59,8 @@ impl Default for ManagerConfig {
             LogLevel: log::LevelFilter::Debug,
             LogTarget: "console".to_string(),
             LogFile: String::new(),
+            LogFileSize: 10240,
+            LogFileNumber: 10,
             DbSize: RELI_HISTORY_MAPSIZE_DEFAULT,
         }
     }
diff --git a/core/bin/unit/manager.rs b/core/bin/unit/manager.rs
index 99366fa..492f3f4 100644
--- a/core/bin/unit/manager.rs
+++ b/core/bin/unit/manager.rs
@@ -475,6 +475,14 @@ impl UmIf for UnitManager {
         self.get_log_target()
     }
 
+    fn get_log_file_size(&self) -> u32 {
+        self.get_log_file_size()
+    }
+
+    fn get_log_file_number(&self) -> u32 {
+        self.get_log_file_number()
+    }
+
     /// set the service's socket fd
     fn service_set_socket_fd(&self, service_name: &str, fd: i32) {
         let service = match self.units_get(service_name) {
@@ -1130,6 +1138,14 @@ impl UnitManager {
     fn get_log_target(&self) -> &str {
         &self.manager_config.LogTarget
     }
+
+    fn get_log_file_size(&self) -> u32 {
+        self.manager_config.LogFileSize
+    }
+
+    fn get_log_file_number(&self) -> u32 {
+        self.manager_config.LogFileNumber
+    }
 }
 
 impl ReStation for UnitManager {
diff --git a/core/lib/unit/umif.rs b/core/lib/unit/umif.rs
index 049013d..c41c211 100644
--- a/core/lib/unit/umif.rs
+++ b/core/lib/unit/umif.rs
@@ -195,6 +195,16 @@ pub trait UmIf {
         ""
     }
 
+    /// get the log file size
+    fn get_log_file_size(&self) -> u32 {
+        0
+    }
+
+    /// get the log file number
+    fn get_log_file_number(&self) -> u32 {
+        0
+    }
+
     /// get the log target config
     fn get_log_target(&self) -> &str {
         ""
-- 
2.33.0

