## Issues Addressed Closes https://github.com/sigp/lighthouse/issues/3101 ## Proposed Changes Add global flag to suppress timestamps in the terminal logger.
This commit is contained in:
parent
3128b5b430
commit
76ba0a1aaf
@ -785,6 +785,7 @@ fn run<T: EthSpec>(
|
|||||||
logfile_debug_level: "trace",
|
logfile_debug_level: "trace",
|
||||||
log_format: None,
|
log_format: None,
|
||||||
log_color: false,
|
log_color: false,
|
||||||
|
disable_log_timestamp: false,
|
||||||
max_log_size: 0,
|
max_log_size: 0,
|
||||||
max_log_number: 0,
|
max_log_number: 0,
|
||||||
compression: false,
|
compression: false,
|
||||||
|
@ -15,6 +15,7 @@ use futures::{future, StreamExt};
|
|||||||
use slog::{error, info, o, warn, Drain, Duplicate, Level, Logger};
|
use slog::{error, info, o, warn, Drain, Duplicate, Level, Logger};
|
||||||
use sloggers::{file::FileLoggerBuilder, types::Format, types::Severity, Build};
|
use sloggers::{file::FileLoggerBuilder, types::Format, types::Severity, Build};
|
||||||
use std::fs::create_dir_all;
|
use std::fs::create_dir_all;
|
||||||
|
use std::io::{Result as IOResult, Write};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use task_executor::{ShutdownReason, TaskExecutor};
|
use task_executor::{ShutdownReason, TaskExecutor};
|
||||||
@ -48,6 +49,7 @@ pub struct LoggerConfig<'a> {
|
|||||||
pub logfile_debug_level: &'a str,
|
pub logfile_debug_level: &'a str,
|
||||||
pub log_format: Option<&'a str>,
|
pub log_format: Option<&'a str>,
|
||||||
pub log_color: bool,
|
pub log_color: bool,
|
||||||
|
pub disable_log_timestamp: bool,
|
||||||
pub max_log_size: u64,
|
pub max_log_size: u64,
|
||||||
pub max_log_number: usize,
|
pub max_log_number: usize,
|
||||||
pub compression: bool,
|
pub compression: bool,
|
||||||
@ -121,6 +123,10 @@ impl<E: EthSpec> EnvironmentBuilder<E> {
|
|||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn log_nothing(_: &mut dyn Write) -> IOResult<()> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
/// Initializes the logger using the specified configuration.
|
/// Initializes the logger using the specified configuration.
|
||||||
/// The logger is "async" because it has a dedicated thread that accepts logs and then
|
/// 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
|
/// asynchronously flushes them to stdout/files/etc. This means the thread that raised the log
|
||||||
@ -149,7 +155,14 @@ impl<E: EthSpec> EnvironmentBuilder<E> {
|
|||||||
.build();
|
.build();
|
||||||
let stdout_decorator =
|
let stdout_decorator =
|
||||||
logging::AlignedTermDecorator::new(stdout_decorator, logging::MAX_MESSAGE_WIDTH);
|
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)
|
slog_async::Async::new(stdout_drain)
|
||||||
.chan_size(LOG_CHANNEL_SIZE)
|
.chan_size(LOG_CHANNEL_SIZE)
|
||||||
.build()
|
.build()
|
||||||
|
@ -145,6 +145,12 @@ fn main() {
|
|||||||
.help("Force outputting colors when emitting logs to the terminal.")
|
.help("Force outputting colors when emitting logs to the terminal.")
|
||||||
.global(true),
|
.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(
|
||||||
Arg::with_name("debug-level")
|
Arg::with_name("debug-level")
|
||||||
.long("debug-level")
|
.long("debug-level")
|
||||||
@ -381,6 +387,8 @@ fn run<E: EthSpec>(
|
|||||||
|
|
||||||
let log_color = matches.is_present("log-color");
|
let log_color = matches.is_present("log-color");
|
||||||
|
|
||||||
|
let disable_log_timestamp = matches.is_present("disable-log-timestamp");
|
||||||
|
|
||||||
let logfile_debug_level = matches
|
let logfile_debug_level = matches
|
||||||
.value_of("logfile-debug-level")
|
.value_of("logfile-debug-level")
|
||||||
.ok_or("Expected --logfile-debug-level flag")?;
|
.ok_or("Expected --logfile-debug-level flag")?;
|
||||||
@ -434,6 +442,7 @@ fn run<E: EthSpec>(
|
|||||||
logfile_debug_level,
|
logfile_debug_level,
|
||||||
log_format,
|
log_format,
|
||||||
log_color,
|
log_color,
|
||||||
|
disable_log_timestamp,
|
||||||
max_log_size: logfile_max_size * 1_024 * 1_024,
|
max_log_size: logfile_max_size * 1_024 * 1_024,
|
||||||
max_log_number: logfile_max_number,
|
max_log_number: logfile_max_number,
|
||||||
compression: logfile_compress,
|
compression: logfile_compress,
|
||||||
|
@ -66,6 +66,7 @@ pub fn run_eth1_sim(matches: &ArgMatches) -> Result<(), String> {
|
|||||||
logfile_debug_level: "debug",
|
logfile_debug_level: "debug",
|
||||||
log_format,
|
log_format,
|
||||||
log_color: false,
|
log_color: false,
|
||||||
|
disable_log_timestamp: false,
|
||||||
max_log_size: 0,
|
max_log_size: 0,
|
||||||
max_log_number: 0,
|
max_log_number: 0,
|
||||||
compression: false,
|
compression: false,
|
||||||
|
@ -51,6 +51,7 @@ pub fn run_no_eth1_sim(matches: &ArgMatches) -> Result<(), String> {
|
|||||||
logfile_debug_level: "debug",
|
logfile_debug_level: "debug",
|
||||||
log_format,
|
log_format,
|
||||||
log_color: false,
|
log_color: false,
|
||||||
|
disable_log_timestamp: false,
|
||||||
max_log_size: 0,
|
max_log_size: 0,
|
||||||
max_log_number: 0,
|
max_log_number: 0,
|
||||||
compression: false,
|
compression: false,
|
||||||
|
@ -52,6 +52,7 @@ fn syncing_sim(
|
|||||||
logfile_debug_level: "debug",
|
logfile_debug_level: "debug",
|
||||||
log_format,
|
log_format,
|
||||||
log_color: false,
|
log_color: false,
|
||||||
|
disable_log_timestamp: false,
|
||||||
max_log_size: 0,
|
max_log_size: 0,
|
||||||
max_log_number: 0,
|
max_log_number: 0,
|
||||||
compression: false,
|
compression: false,
|
||||||
|
Loading…
Reference in New Issue
Block a user