mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-03 00:31:50 +00:00
@@ -13,6 +13,9 @@ use tracing_subscriber::layer::Context;
|
|||||||
use tracing_subscriber::registry::LookupSpan;
|
use tracing_subscriber::registry::LookupSpan;
|
||||||
use tracing_subscriber::Layer;
|
use tracing_subscriber::Layer;
|
||||||
|
|
||||||
|
const FIXED_MESSAGE_WIDTH: usize = 44;
|
||||||
|
const ALIGNED_LEVEL_WIDTH: usize = 5;
|
||||||
|
|
||||||
pub struct LoggingLayer {
|
pub struct LoggingLayer {
|
||||||
pub non_blocking_writer: NonBlocking,
|
pub non_blocking_writer: NonBlocking,
|
||||||
_guard: WorkerGuard,
|
_guard: WorkerGuard,
|
||||||
@@ -368,13 +371,18 @@ fn build_log_text<'a, S>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let level_str = if use_color {
|
let pad = if plain_level_str.len() < ALIGNED_LEVEL_WIDTH {
|
||||||
color_level_str
|
" "
|
||||||
} else {
|
} else {
|
||||||
plain_level_str
|
""
|
||||||
|
};
|
||||||
|
|
||||||
|
let level_str = if use_color {
|
||||||
|
format!("{}{}", color_level_str, pad)
|
||||||
|
} else {
|
||||||
|
format!("{}{}", plain_level_str, pad)
|
||||||
};
|
};
|
||||||
|
|
||||||
let fixed_message_width = 44;
|
|
||||||
let message_len = visitor.message.len();
|
let message_len = visitor.message.len();
|
||||||
|
|
||||||
let message_content = if use_color {
|
let message_content = if use_color {
|
||||||
@@ -383,7 +391,7 @@ fn build_log_text<'a, S>(
|
|||||||
visitor.message.clone()
|
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 {
|
let extra_color_len = if use_color {
|
||||||
bold_start.len() + bold_end.len()
|
bold_start.len() + bold_end.len()
|
||||||
} else {
|
} else {
|
||||||
@@ -392,7 +400,7 @@ fn build_log_text<'a, S>(
|
|||||||
format!(
|
format!(
|
||||||
"{:<width$}",
|
"{:<width$}",
|
||||||
message_content,
|
message_content,
|
||||||
width = fixed_message_width + extra_color_len
|
width = FIXED_MESSAGE_WIDTH + extra_color_len
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
message_content.clone()
|
message_content.clone()
|
||||||
|
|||||||
Reference in New Issue
Block a user