Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions common/logging/src/tracing_logging_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -392,7 +400,7 @@ fn build_log_text<'a, S>(
format!(
"{:<width$}",
message_content,
width = fixed_message_width + extra_color_len
width = FIXED_MESSAGE_WIDTH + extra_color_len
)
} else {
message_content.clone()
Expand Down
Loading