mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-09 19:51:47 +00:00
#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.
69 lines
2.4 KiB
Rust
69 lines
2.4 KiB
Rust
use metrics::{try_create_int_counter, IntCounter, Result as MetricsResult};
|
|
use std::sync::LazyLock;
|
|
use std::time::{Duration, Instant};
|
|
use tracing_subscriber::EnvFilter;
|
|
|
|
pub const MAX_MESSAGE_WIDTH: usize = 40;
|
|
|
|
pub mod macros;
|
|
mod sse_logging_components;
|
|
mod tracing_libp2p_discv5_logging_layer;
|
|
pub mod tracing_logging_layer;
|
|
mod tracing_metrics_layer;
|
|
mod utils;
|
|
|
|
pub use sse_logging_components::SSELoggingComponents;
|
|
pub use tracing_libp2p_discv5_logging_layer::{
|
|
create_libp2p_discv5_tracing_layer, Libp2pDiscv5TracingLayer,
|
|
};
|
|
pub use tracing_logging_layer::LoggingLayer;
|
|
pub use tracing_metrics_layer::MetricsLayer;
|
|
pub use utils::build_workspace_filter;
|
|
|
|
/// The minimum interval between log messages indicating that a queue is full.
|
|
const LOG_DEBOUNCE_INTERVAL: Duration = Duration::from_secs(30);
|
|
|
|
pub static INFOS_TOTAL: LazyLock<MetricsResult<IntCounter>> =
|
|
LazyLock::new(|| try_create_int_counter("info_total", "Count of infos logged"));
|
|
pub static WARNS_TOTAL: LazyLock<MetricsResult<IntCounter>> =
|
|
LazyLock::new(|| try_create_int_counter("warn_total", "Count of warns logged"));
|
|
pub static ERRORS_TOTAL: LazyLock<MetricsResult<IntCounter>> =
|
|
LazyLock::new(|| try_create_int_counter("error_total", "Count of errors logged"));
|
|
pub static CRITS_TOTAL: LazyLock<MetricsResult<IntCounter>> =
|
|
LazyLock::new(|| try_create_int_counter("crit_total", "Count of crits logged"));
|
|
|
|
/// Provides de-bounce functionality for logging.
|
|
#[derive(Default)]
|
|
pub struct TimeLatch(Option<Instant>);
|
|
|
|
impl TimeLatch {
|
|
/// Only returns true once every `LOG_DEBOUNCE_INTERVAL`.
|
|
pub fn elapsed(&mut self) -> bool {
|
|
let now = Instant::now();
|
|
|
|
let is_elapsed = self.0.is_some_and(|elapse_time| now > elapse_time);
|
|
|
|
if is_elapsed || self.0.is_none() {
|
|
self.0 = Some(now + LOG_DEBOUNCE_INTERVAL);
|
|
}
|
|
|
|
is_elapsed
|
|
}
|
|
}
|
|
|
|
/// Return a tracing subscriber suitable for test usage.
|
|
///
|
|
/// By default no logs will be printed, but they can be enabled via
|
|
/// the `test_logger` feature. This feature can be enabled for any
|
|
/// dependent crate by passing `--features logging/test_logger`, e.g.
|
|
/// ```bash
|
|
/// cargo test -p beacon_chain --features logging/test_logger
|
|
/// ```
|
|
pub fn create_test_tracing_subscriber() {
|
|
if cfg!(feature = "test_logger") {
|
|
let _ = tracing_subscriber::fmt()
|
|
.with_env_filter(EnvFilter::try_new("debug").unwrap())
|
|
.try_init();
|
|
}
|
|
}
|