Svecco commented on code in PR #2452:
URL: https://github.com/apache/iggy/pull/2452#discussion_r2656218209


##########
core/server/src/log/logger.rs:
##########
@@ -397,26 +444,199 @@ impl Logging {
         Format::default().with_thread_names(true)
     }
 
-    fn _install_log_rotation_handler(&self) {
-        todo!("Implement log rotation handler based on size and retention 
time");
-    }
-
     fn print_build_info() {
         if option_env!("IGGY_CI_BUILD") == Some("true") {
             let hash = option_env!("VERGEN_GIT_SHA").unwrap_or("unknown");
             let built_at = 
option_env!("VERGEN_BUILD_TIMESTAMP").unwrap_or("unknown");
             let rust_version = 
option_env!("VERGEN_RUSTC_SEMVER").unwrap_or("unknown");
             let target = 
option_env!("VERGEN_CARGO_TARGET_TRIPLE").unwrap_or("unknown");
             info!(
-                "Version: {VERSION}, hash: {}, built at: {} using rust 
version: {} for target: {}",
-                hash, built_at, rust_version, target
+                "Version: {VERSION}, hash: {hash}, built at: {built_at} using 
rust version: {rust_version} for target: {target}"
             );
         } else {
             info!(
                 "It seems that you are a developer. Environment variable 
IGGY_CI_BUILD is not set to 'true', skipping build info print."
             )
         }
     }
+
+    fn calculate_max_files(max_total_size_bytes: u64, max_file_size_bytes: 
u64) -> usize {
+        if max_file_size_bytes == 0 {
+            return 10;
+        }
+
+        let max_files = max_total_size_bytes / max_file_size_bytes;
+        max_files.clamp(1, 1000) as usize
+    }
+
+    fn _install_log_rotation_handler(&self, config: &LoggingConfig, logs_path: 
Option<&PathBuf>) {
+        if let Some(logs_path) = logs_path {
+            let path = logs_path.to_path_buf();
+            let max_size = config.max_size.as_bytes_u64();
+            let retention = config.retention.get_duration();
+            let check_interval = config.rotation_check_interval;
+            let should_stop = Arc::clone(&self.rotation_should_stop);
+
+            std::thread::spawn(move || {
+                loop {
+                    if should_stop.load(Ordering::Relaxed) {
+                        break;
+                    }
+
+                    std::thread::sleep(Duration::from_secs(check_interval));
+
+                    if should_stop.load(Ordering::Relaxed) {
+                        break;
+                    }
+
+                    Self::cleanup_log_files(&path, retention, max_size);

Review Comment:
   Fixed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to