improve code for logger and fix typo (#272)

This commit is contained in:
houseme
2025-07-21 15:20:36 +08:00
committed by GitHub
parent f7d30da9e0
commit 3f095e75cb
8 changed files with 34 additions and 16 deletions

View File

@@ -31,7 +31,7 @@ pub struct ListPathRawOptions {
pub fallback_disks: Vec<Option<DiskStore>>, pub fallback_disks: Vec<Option<DiskStore>>,
pub bucket: String, pub bucket: String,
pub path: String, pub path: String,
pub recursice: bool, pub recursive: bool,
pub filter_prefix: Option<String>, pub filter_prefix: Option<String>,
pub forward_to: Option<String>, pub forward_to: Option<String>,
pub min_disks: usize, pub min_disks: usize,
@@ -52,7 +52,7 @@ impl Clone for ListPathRawOptions {
fallback_disks: self.fallback_disks.clone(), fallback_disks: self.fallback_disks.clone(),
bucket: self.bucket.clone(), bucket: self.bucket.clone(),
path: self.path.clone(), path: self.path.clone(),
recursice: self.recursice, recursive: self.recursive,
filter_prefix: self.filter_prefix.clone(), filter_prefix: self.filter_prefix.clone(),
forward_to: self.forward_to.clone(), forward_to: self.forward_to.clone(),
min_disks: self.min_disks, min_disks: self.min_disks,
@@ -85,7 +85,7 @@ pub async fn list_path_raw(mut rx: B_Receiver<bool>, opts: ListPathRawOptions) -
let wakl_opts = WalkDirOptions { let wakl_opts = WalkDirOptions {
bucket: opts_clone.bucket.clone(), bucket: opts_clone.bucket.clone(),
base_dir: opts_clone.path.clone(), base_dir: opts_clone.path.clone(),
recursive: opts_clone.recursice, recursive: opts_clone.recursive,
report_notfound: opts_clone.report_not_found, report_notfound: opts_clone.report_not_found,
filter_prefix: opts_clone.filter_prefix.clone(), filter_prefix: opts_clone.filter_prefix.clone(),
forward_to: opts_clone.forward_to.clone(), forward_to: opts_clone.forward_to.clone(),
@@ -133,7 +133,7 @@ pub async fn list_path_raw(mut rx: B_Receiver<bool>, opts: ListPathRawOptions) -
WalkDirOptions { WalkDirOptions {
bucket: opts_clone.bucket.clone(), bucket: opts_clone.bucket.clone(),
base_dir: opts_clone.path.clone(), base_dir: opts_clone.path.clone(),
recursive: opts_clone.recursice, recursive: opts_clone.recursive,
report_notfound: opts_clone.report_not_found, report_notfound: opts_clone.report_not_found,
filter_prefix: opts_clone.filter_prefix.clone(), filter_prefix: opts_clone.filter_prefix.clone(),
forward_to: opts_clone.forward_to.clone(), forward_to: opts_clone.forward_to.clone(),

View File

@@ -1262,7 +1262,7 @@ impl FolderScanner {
disks: self.disks.clone(), disks: self.disks.clone(),
bucket: bucket.clone(), bucket: bucket.clone(),
path: prefix.clone(), path: prefix.clone(),
recursice: true, recursive: true,
report_not_found: true, report_not_found: true,
min_disks: self.disks_quorum, min_disks: self.disks_quorum,
agreed: Some(Box::new(move |entry: MetaCacheEntry| { agreed: Some(Box::new(move |entry: MetaCacheEntry| {

View File

@@ -1355,7 +1355,7 @@ impl SetDisks {
disks: disks.iter().cloned().map(Some).collect(), disks: disks.iter().cloned().map(Some).collect(),
bucket: bucket_info.name.clone(), bucket: bucket_info.name.clone(),
path: bucket_info.prefix.clone(), path: bucket_info.prefix.clone(),
recursice: true, recursive: true,
min_disks: listing_quorum, min_disks: listing_quorum,
agreed: Some(Box::new(move |entry: MetaCacheEntry| Box::pin(cb1(entry)))), agreed: Some(Box::new(move |entry: MetaCacheEntry| Box::pin(cb1(entry)))),
partial: Some(Box::new(move |entries: MetaCacheEntries, _: &[Option<DiskError>]| { partial: Some(Box::new(move |entries: MetaCacheEntries, _: &[Option<DiskError>]| {

View File

@@ -1172,7 +1172,7 @@ impl SetDisks {
ListPathRawOptions { ListPathRawOptions {
disks: disks.iter().cloned().map(Some).collect(), disks: disks.iter().cloned().map(Some).collect(),
bucket: bucket.clone(), bucket: bucket.clone(),
recursice: true, recursive: true,
min_disks: listing_quorum, min_disks: listing_quorum,
agreed: Some(Box::new(move |entry: MetaCacheEntry| { agreed: Some(Box::new(move |entry: MetaCacheEntry| {
info!("list_objects_to_rebalance: agreed: {:?}", &entry.name); info!("list_objects_to_rebalance: agreed: {:?}", &entry.name);

View File

@@ -2306,7 +2306,7 @@ impl SetDisks {
Some(filter_prefix.to_string()) Some(filter_prefix.to_string())
} }
}, },
recursice: true, recursive: true,
forward_to: None, forward_to: None,
min_disks: 1, min_disks: 1,
report_not_found: false, report_not_found: false,
@@ -3836,7 +3836,7 @@ impl SetDisks {
disks, disks,
fallback_disks, fallback_disks,
bucket: bucket.clone(), bucket: bucket.clone(),
recursice: true, recursive: true,
forward_to, forward_to,
min_disks: 1, min_disks: 1,
report_not_found: false, report_not_found: false,

View File

@@ -776,7 +776,7 @@ impl ECStore {
fallback_disks: fallback_disks.iter().cloned().map(Some).collect(), fallback_disks: fallback_disks.iter().cloned().map(Some).collect(),
bucket: bucket.to_owned(), bucket: bucket.to_owned(),
path, path,
recursice: true, recursive: true,
filter_prefix: Some(filter_prefix), filter_prefix: Some(filter_prefix),
forward_to: opts.marker.clone(), forward_to: opts.marker.clone(),
min_disks: listing_quorum, min_disks: listing_quorum,
@@ -1286,7 +1286,7 @@ impl SetDisks {
fallback_disks: fallback_disks.iter().cloned().map(Some).collect(), fallback_disks: fallback_disks.iter().cloned().map(Some).collect(),
bucket: opts.bucket, bucket: opts.bucket,
path: opts.base_dir, path: opts.base_dir,
recursice: opts.recursive, recursive: opts.recursive,
filter_prefix: opts.filter_prefix, filter_prefix: opts.filter_prefix,
forward_to: opts.marker, forward_to: opts.marker,
min_disks: listing_quorum, min_disks: listing_quorum,

View File

@@ -36,6 +36,7 @@ use rustfs_config::{
use rustfs_utils::get_local_ip_with_default; use rustfs_utils::get_local_ip_with_default;
use smallvec::SmallVec; use smallvec::SmallVec;
use std::borrow::Cow; use std::borrow::Cow;
use std::fs;
use std::io::IsTerminal; use std::io::IsTerminal;
use tracing::info; use tracing::info;
use tracing_error::ErrorLayer; use tracing_error::ErrorLayer;
@@ -295,6 +296,21 @@ pub(crate) fn init_telemetry(config: &OtelConfig) -> OtelGuard {
let log_directory = config.log_directory.as_deref().unwrap_or(DEFAULT_LOG_DIR); let log_directory = config.log_directory.as_deref().unwrap_or(DEFAULT_LOG_DIR);
let log_filename = config.log_filename.as_deref().unwrap_or(service_name); let log_filename = config.log_filename.as_deref().unwrap_or(service_name);
if let Err(e) = fs::create_dir_all(log_directory) {
eprintln!("Failed to create log directory {log_directory}: {e}");
}
#[cfg(unix)]
{
// Linux/macOS Setting Permissions
// Set the log directory permissions to 755 (rwxr-xr-x)
use std::fs::Permissions;
use std::os::unix::fs::PermissionsExt;
match fs::set_permissions(log_directory, Permissions::from_mode(0o755)) {
Ok(_) => eprintln!("Log directory permissions set to 755: {log_directory}"),
Err(e) => eprintln!("Failed to set log directory permissions {log_directory}: {e}"),
}
}
// Build log cutting conditions // Build log cutting conditions
let rotation_criterion = match (config.log_rotation_time.as_deref(), config.log_rotation_size_mb) { let rotation_criterion = match (config.log_rotation_time.as_deref(), config.log_rotation_size_mb) {
// Cut by time and size at the same time // Cut by time and size at the same time
@@ -354,13 +370,15 @@ pub(crate) fn init_telemetry(config: &OtelConfig) -> OtelGuard {
FileSpec::default() FileSpec::default()
.directory(log_directory) .directory(log_directory)
.basename(log_filename) .basename(log_filename)
.suffix("log"), .suppress_timestamp(),
) )
.rotate(rotation_criterion, Naming::TimestampsDirect, Cleanup::KeepLogFiles(keep_files.into())) .rotate(rotation_criterion, Naming::TimestampsDirect, Cleanup::KeepLogFiles(keep_files.into()))
.format_for_files(format_for_file) // Add a custom formatting function for file output .format_for_files(format_for_file) // Add a custom formatting function for file output
.duplicate_to_stdout(level_filter) // Use dynamic levels .duplicate_to_stdout(level_filter) // Use dynamic levels
.format_for_stdout(format_with_color) // Add a custom formatting function for terminal output .format_for_stdout(format_with_color) // Add a custom formatting function for terminal output
.write_mode(WriteMode::Async) .write_mode(WriteMode::BufferAndFlush)
.append() // Avoid clearing existing logs at startup
.print_message() // Startup information output to console
.start(); .start();
if let Ok(logger) = flexi_logger_result { if let Ok(logger) = flexi_logger_result {
@@ -420,7 +438,7 @@ fn format_with_color(w: &mut dyn std::io::Write, now: &mut DeferredNow, record:
writeln!( writeln!(
w, w,
"[{}] {} [{}] [{}:{}] [{}:{}] {}", "[{}] {} [{}] [{}:{}] [{}:{}] {}",
now.now().format("%Y-%m-%d %H:%M:%S%.6f"), now.now().format(flexi_logger::TS_DASHES_BLANK_COLONS_DOT_BLANK),
level_style.paint(level.to_string()), level_style.paint(level.to_string()),
Color::Magenta.paint(record.target()), Color::Magenta.paint(record.target()),
Color::Blue.paint(record.file().unwrap_or("unknown")), Color::Blue.paint(record.file().unwrap_or("unknown")),
@@ -444,7 +462,7 @@ fn format_for_file(w: &mut dyn std::io::Write, now: &mut DeferredNow, record: &R
writeln!( writeln!(
w, w,
"[{}] {} [{}] [{}:{}] [{}:{}] {}", "[{}] {} [{}] [{}:{}] [{}:{}] {}",
now.now().format("%Y-%m-%d %H:%M:%S%.6f"), now.now().format(flexi_logger::TS_DASHES_BLANK_COLONS_DOT_BLANK),
level, level,
record.target(), record.target(),
record.file().unwrap_or("unknown"), record.file().unwrap_or("unknown"),

View File

@@ -64,7 +64,7 @@ export RUSTFS_OBS_LOG_DIRECTORY="$current_dir/deploy/logs" # Log directory
export RUSTFS_OBS_LOG_ROTATION_TIME="minute" # Log rotation time unit, can be "second", "minute", "hour", "day" export RUSTFS_OBS_LOG_ROTATION_TIME="minute" # Log rotation time unit, can be "second", "minute", "hour", "day"
export RUSTFS_OBS_LOG_ROTATION_SIZE_MB=1 # Log rotation size in MB export RUSTFS_OBS_LOG_ROTATION_SIZE_MB=1 # Log rotation size in MB
export RUSTFS_SINKS_FILE_PATH="$current_dir/deploy/logs/rustfs.log" export RUSTFS_SINKS_FILE_PATH="$current_dir/deploy/logs"
export RUSTFS_SINKS_FILE_BUFFER_SIZE=12 export RUSTFS_SINKS_FILE_BUFFER_SIZE=12
export RUSTFS_SINKS_FILE_FLUSH_INTERVAL_MS=1000 export RUSTFS_SINKS_FILE_FLUSH_INTERVAL_MS=1000
export RUSTFS_SINKS_FILE_FLUSH_THRESHOLD=100 export RUSTFS_SINKS_FILE_FLUSH_THRESHOLD=100