Files
lighthouse/common/logging/src/utils.rs
Mac L 4839ed620f Tracing cleanup (#7168)
#7153
#7146
#7147
#7148 -> Thanks to @ackintosh


  This PR does the following:
1. Disable logging to file when using either `--logfile-max-number 0` or `--logfile-max-size 0`. Note that disabling the log file in this way will also disable `discv5` and `libp2p` logging.
1.  `discv5` and `libp2p` logging will be disabled by default unless running `beacon_node` or `boot_node`. This also should fix the VC panic we were seeing.
1. Removes log rotation and compression from `libp2p` and `discv5` logs. It is now limited to 1 file and will rotate based on the value of the `--logfile-max-size` flag. We could potentially add flags specifically to control the size/number of these, however I felt a single log file was sufficient. Perhaps @AgeManning has opinions about this?
1. Removes all dependency logging and references to `dep_log`.
1.  Introduces workspace filtering to file and stdout. This explicitly allows logs from members of the Lighthouse workspace, disallowing all others. It uses a proc macro which pulls the member list from cargo metadata at compile time. This might be over-engineered but my hope is that this list will not require maintenance.
1. Unifies file and stdout JSON format. With slog, the formats were slightly different. @threehrsleep worked to maintain that format difference, to ensure there was no breaking changes. If these format differences are actually problematic we can restore it, however I felt the added complexity wasn't worth it.
1. General code improvements and cleanup.
2025-04-01 10:51:09 +00:00

32 lines
1.0 KiB
Rust

use std::collections::HashSet;
use tracing_subscriber::filter::FilterFn;
use workspace_members::workspace_crates;
const WORKSPACE_CRATES: &[&str] = workspace_crates!();
/// Constructs a filter which only permits logging from crates which are members of the workspace.
pub fn build_workspace_filter(
) -> Result<FilterFn<impl Fn(&tracing::Metadata) -> bool + Clone>, String> {
let workspace_crates: HashSet<&str> = WORKSPACE_CRATES.iter().copied().collect();
Ok(tracing_subscriber::filter::FilterFn::new(move |metadata| {
let target_crate = metadata.target().split("::").next().unwrap_or("");
workspace_crates.contains(target_crate)
}))
}
/// Function to filter out ascii control codes.
///
/// This helps to keep log formatting consistent.
/// Whitespace and padding control codes are excluded.
pub fn is_ascii_control(character: &u8) -> bool {
matches!(
character,
b'\x00'..=b'\x08' |
b'\x0b'..=b'\x0c' |
b'\x0e'..=b'\x1f' |
b'\x7f' |
b'\x81'..=b'\x9f'
)
}