diff --git a/common/logging/src/tracing_logging_layer.rs b/common/logging/src/tracing_logging_layer.rs index 810f7e960e9..c3784a8f621 100644 --- a/common/logging/src/tracing_logging_layer.rs +++ b/common/logging/src/tracing_logging_layer.rs @@ -13,6 +13,9 @@ use tracing_subscriber::layer::Context; use tracing_subscriber::registry::LookupSpan; use tracing_subscriber::Layer; +const FIXED_MESSAGE_WIDTH: usize = 44; +const ALIGNED_LEVEL_WIDTH: usize = 5; + pub struct LoggingLayer { pub non_blocking_writer: NonBlocking, _guard: WorkerGuard, @@ -368,13 +371,18 @@ fn build_log_text<'a, S>( } } + let pad = if plain_level_str.len() < ALIGNED_LEVEL_WIDTH { + " " + } else { + "" + }; + let level_str = if use_color { - color_level_str + format!("{}{}", color_level_str, pad) } else { - plain_level_str + format!("{}{}", plain_level_str, pad) }; - let fixed_message_width = 44; let message_len = visitor.message.len(); let message_content = if use_color { @@ -383,7 +391,7 @@ fn build_log_text<'a, S>( visitor.message.clone() }; - let padded_message = if message_len < fixed_message_width { + let padded_message = if message_len < FIXED_MESSAGE_WIDTH { let extra_color_len = if use_color { bold_start.len() + bold_end.len() } else { @@ -392,7 +400,7 @@ fn build_log_text<'a, S>( format!( "{: