Svecco commented on code in PR #2452:
URL: https://github.com/apache/iggy/pull/2452#discussion_r2656215345
##########
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 || {
Review Comment:
It can be shutdown gracefully now, debug logs looks like:
```console
2026-01-01T09:31:58.298319Z INFO main iggy_server: Shard 1 exited
successfully
2026-01-01T09:31:58.298327Z INFO main iggy_server: Shard 7 exited
successfully
2026-01-01T09:31:58.298332Z INFO main iggy_server: Shard 14 exited
successfully
2026-01-01T09:31:58.298357Z INFO main iggy_server: Shard 9 exited
successfully
2026-01-01T09:31:58.298474Z INFO main iggy_server: All shards have shut
down. Iggy server is exiting. (shutdown took 1 ms)
2026-01-01T09:31:58.298562Z DEBUG main server::log::logger: Set
rotation_should_stop to true for log rotation thread
2026-01-01T09:31:58.298591Z DEBUG log-rotation server::log::logger: Log
rotation thread received channel stop signal, exiting
2026-01-01T09:31:58.298611Z DEBUG log-rotation server::log::logger: Log
rotation thread exited gracefully
2026-01-01T09:31:58.298647Z DEBUG main server::log::logger: Log
rotation thread joined successfully
```
##########
core/server/Cargo.toml:
##########
@@ -68,10 +68,10 @@ error_set = { workspace = true }
figlet-rs = { workspace = true }
figment = { workspace = true }
flume = { workspace = true }
+fs2 = "0.4"
Review Comment:
Done
--
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]