diff --git a/lcli/src/main.rs b/lcli/src/main.rs index 84b951e3f..11a23fe0b 100644 --- a/lcli/src/main.rs +++ b/lcli/src/main.rs @@ -785,6 +785,7 @@ fn run( logfile_debug_level: "trace", log_format: None, log_color: false, + disable_log_timestamp: false, max_log_size: 0, max_log_number: 0, compression: false, diff --git a/lighthouse/environment/src/lib.rs b/lighthouse/environment/src/lib.rs index 679964c0d..46348e63b 100644 --- a/lighthouse/environment/src/lib.rs +++ b/lighthouse/environment/src/lib.rs @@ -15,6 +15,7 @@ use futures::{future, StreamExt}; use slog::{error, info, o, warn, Drain, Duplicate, Level, Logger}; use sloggers::{file::FileLoggerBuilder, types::Format, types::Severity, Build}; use std::fs::create_dir_all; +use std::io::{Result as IOResult, Write}; use std::path::PathBuf; use std::sync::Arc; use task_executor::{ShutdownReason, TaskExecutor}; @@ -48,6 +49,7 @@ pub struct LoggerConfig<'a> { pub logfile_debug_level: &'a str, pub log_format: Option<&'a str>, pub log_color: bool, + pub disable_log_timestamp: bool, pub max_log_size: u64, pub max_log_number: usize, pub compression: bool, @@ -121,6 +123,10 @@ impl EnvironmentBuilder { Ok(self) } + fn log_nothing(_: &mut dyn Write) -> IOResult<()> { + Ok(()) + } + /// Initializes the logger using the specified configuration. /// The logger is "async" because it has a dedicated thread that accepts logs and then /// asynchronously flushes them to stdout/files/etc. This means the thread that raised the log @@ -149,7 +155,14 @@ impl EnvironmentBuilder { .build(); let stdout_decorator = logging::AlignedTermDecorator::new(stdout_decorator, logging::MAX_MESSAGE_WIDTH); - let stdout_drain = slog_term::FullFormat::new(stdout_decorator).build().fuse(); + let stdout_drain = slog_term::FullFormat::new(stdout_decorator); + let stdout_drain = if config.disable_log_timestamp { + stdout_drain.use_custom_timestamp(Self::log_nothing) + } else { + stdout_drain + } + .build() + .fuse(); slog_async::Async::new(stdout_drain) .chan_size(LOG_CHANNEL_SIZE) .build() diff --git a/lighthouse/src/main.rs b/lighthouse/src/main.rs index 7897494cc..341e1a91d 100644 --- a/lighthouse/src/main.rs +++ b/lighthouse/src/main.rs @@ -145,6 +145,12 @@ fn main() { .help("Force outputting colors when emitting logs to the terminal.") .global(true), ) + .arg( + Arg::with_name("disable-log-timestamp") + .long("disable-log-timestamp") + .help("If present, do not include timestamps in logging output.") + .global(true), + ) .arg( Arg::with_name("debug-level") .long("debug-level") @@ -381,6 +387,8 @@ fn run( let log_color = matches.is_present("log-color"); + let disable_log_timestamp = matches.is_present("disable-log-timestamp"); + let logfile_debug_level = matches .value_of("logfile-debug-level") .ok_or("Expected --logfile-debug-level flag")?; @@ -434,6 +442,7 @@ fn run( logfile_debug_level, log_format, log_color, + disable_log_timestamp, max_log_size: logfile_max_size * 1_024 * 1_024, max_log_number: logfile_max_number, compression: logfile_compress, diff --git a/testing/simulator/src/eth1_sim.rs b/testing/simulator/src/eth1_sim.rs index 613573cd0..5e346d546 100644 --- a/testing/simulator/src/eth1_sim.rs +++ b/testing/simulator/src/eth1_sim.rs @@ -66,6 +66,7 @@ pub fn run_eth1_sim(matches: &ArgMatches) -> Result<(), String> { logfile_debug_level: "debug", log_format, log_color: false, + disable_log_timestamp: false, max_log_size: 0, max_log_number: 0, compression: false, diff --git a/testing/simulator/src/no_eth1_sim.rs b/testing/simulator/src/no_eth1_sim.rs index 28b871984..57e2e01eb 100644 --- a/testing/simulator/src/no_eth1_sim.rs +++ b/testing/simulator/src/no_eth1_sim.rs @@ -51,6 +51,7 @@ pub fn run_no_eth1_sim(matches: &ArgMatches) -> Result<(), String> { logfile_debug_level: "debug", log_format, log_color: false, + disable_log_timestamp: false, max_log_size: 0, max_log_number: 0, compression: false, diff --git a/testing/simulator/src/sync_sim.rs b/testing/simulator/src/sync_sim.rs index 07d774b8d..af5ba95e0 100644 --- a/testing/simulator/src/sync_sim.rs +++ b/testing/simulator/src/sync_sim.rs @@ -52,6 +52,7 @@ fn syncing_sim( logfile_debug_level: "debug", log_format, log_color: false, + disable_log_timestamp: false, max_log_size: 0, max_log_number: 0, compression: false,