Replace prints with logs and fix grammar (#437)

* refactor: replace print statements with proper logging and fix grammar

- Fix English grammar errors in existing log messages
- Add tracing imports where needed
- Improve log message clarity and consistency
- Follow project logging best practices using tracing crate

* fix: resolve clippy warnings and format code

- Fix unused import warnings by making test imports conditional with #[cfg(test)]
- Fix unused variable warning by prefixing with underscore
- Run cargo fmt to fix formatting issues
- Ensure all code passes clippy checks with -D warnings flag

* refactor: move tracing::debug import into test module

Move the tracing::debug import from file-level #[cfg(test)] into the test module itself for better code organization and consistency with other test modules

* Checkpoint before follow-up message

Co-authored-by: anzhengchao <anzhengchao@gmail.com>

* refactor: move tracing::debug import into test module in user_agent.rs

Complete the refactoring by moving the tracing::debug import from file-level #[cfg(test)] into the test module for consistency across all test files

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
This commit is contained in:
安正超
2025-08-21 05:49:40 +08:00
committed by GitHub
parent a104c33974
commit 357cced49c
10 changed files with 43 additions and 42 deletions
+2 -1
View File
@@ -110,6 +110,7 @@ pub fn uvarint(buf: &[u8]) -> (u64, isize) {
mod tests {
use super::*;
use tokio::io::BufReader;
use tracing::debug;
#[tokio::test]
async fn test_read_full_exact() {
@@ -130,7 +131,7 @@ mod tests {
rev[total - n..total].copy_from_slice(&buf[..n]);
count += 1;
println!("count: {count}, total: {total}, n: {n}");
debug!("Read progress - count: {}, total: {}, bytes read: {}", count, total, n);
}
assert_eq!(total, size);
+2 -1
View File
@@ -170,6 +170,7 @@ fn read_stat(file_name: &str) -> std::io::Result<Vec<u64>> {
#[cfg(test)]
mod test {
use super::get_drive_stats;
use tracing::debug;
#[ignore] // FIXME: failed in github actions
#[test]
@@ -177,6 +178,6 @@ mod test {
let major = 7;
let minor = 11;
let s = get_drive_stats(major, minor).unwrap();
println!("{s:?}");
debug!("Drive stats for major: {}, minor: {} - {:?}", major, minor, s);
}
}
+2 -4
View File
@@ -74,8 +74,7 @@ mod tests {
let temp_dir = tempfile::tempdir().unwrap();
let info = get_info(temp_dir.path()).unwrap();
println!("Disk Info: {info:?}");
// Verify disk info is valid
assert!(info.total > 0);
assert!(info.free > 0);
assert!(info.used > 0);
@@ -109,10 +108,9 @@ mod tests {
let path1 = temp_dir1.path().to_str().unwrap();
let path2 = temp_dir2.path().to_str().unwrap();
let result = same_disk(path1, path2).unwrap();
let _result = same_disk(path1, path2).unwrap();
// Since both temporary directories are created in the same file system,
// they should be on the same disk in most cases
println!("Path1: {path1}, Path2: {path2}, Same disk: {result}");
// Test passes if the function doesn't panic - the actual result depends on test environment
}
+3 -3
View File
@@ -279,9 +279,9 @@ mod tests {
#[test]
fn test_base_dir_from_prefix() {
let a = "da/";
println!("---- in {a}");
let a = base_dir_from_prefix(a);
println!("---- out {a}");
// Test base_dir_from_prefix function
let result = base_dir_from_prefix(a);
assert!(!result.is_empty());
}
#[test]
+10 -9
View File
@@ -155,12 +155,13 @@ pub fn get_user_agent(service: ServiceType) -> String {
mod tests {
use super::*;
use rustfs_config::VERSION;
use tracing::debug;
#[test]
fn test_user_agent_format_basis() {
let ua = get_user_agent(ServiceType::Basis);
assert!(ua.starts_with("Mozilla/5.0"));
assert!(ua.contains(&format!("RustFS/{VERSION}").to_string()));
println!("User-Agent: {ua}");
debug!("Basic User-Agent: {}", ua);
}
#[test]
@@ -168,7 +169,7 @@ mod tests {
let ua = get_user_agent(ServiceType::Core);
assert!(ua.starts_with("Mozilla/5.0"));
assert!(ua.contains(&format!("RustFS/{VERSION} (core)").to_string()));
println!("User-Agent: {ua}");
debug!("Core User-Agent: {}", ua);
}
#[test]
@@ -176,7 +177,7 @@ mod tests {
let ua = get_user_agent(ServiceType::Event);
assert!(ua.starts_with("Mozilla/5.0"));
assert!(ua.contains(&format!("RustFS/{VERSION} (event)").to_string()));
println!("User-Agent: {ua}");
debug!("Event User-Agent: {}", ua);
}
#[test]
@@ -184,7 +185,7 @@ mod tests {
let ua = get_user_agent(ServiceType::Logger);
assert!(ua.starts_with("Mozilla/5.0"));
assert!(ua.contains(&format!("RustFS/{VERSION} (logger)").to_string()));
println!("User-Agent: {ua}");
debug!("Logger User-Agent: {}", ua);
}
#[test]
@@ -192,7 +193,7 @@ mod tests {
let ua = get_user_agent(ServiceType::Custom("monitor".to_string()));
assert!(ua.starts_with("Mozilla/5.0"));
assert!(ua.contains(&format!("RustFS/{VERSION} (monitor)").to_string()));
println!("User-Agent: {ua}");
debug!("Monitor User-Agent: {}", ua);
}
#[test]
@@ -203,9 +204,9 @@ mod tests {
let ua_logger = get_user_agent(ServiceType::Logger);
let ua_custom = get_user_agent(ServiceType::Custom("monitor".to_string()));
println!("Core User-Agent: {ua_core}");
println!("Event User-Agent: {ua_event}");
println!("Logger User-Agent: {ua_logger}");
println!("Custom User-Agent: {ua_custom}");
debug!("Core User-Agent: {}", ua_core);
debug!("Event User-Agent: {}", ua_event);
debug!("Logger User-Agent: {}", ua_logger);
debug!("Custom User-Agent: {}", ua_custom);
}
}