Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion beacon_node/client/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use directory::DEFAULT_ROOT_DIR;
use environment::LoggerConfig;
use network::NetworkConfig;
use sensitive_url::SensitiveUrl;
use serde_derive::{Deserialize, Serialize};
use std::fs;
use std::path::PathBuf;
use types::{Graffiti, PublicKeyBytes};

/// Default directory name for the freezer database under the top-level data dir.
const DEFAULT_FREEZER_DB_DIR: &str = "freezer_db";

Expand Down Expand Up @@ -72,6 +72,7 @@ pub struct Config {
pub http_metrics: http_metrics::Config,
pub monitoring_api: Option<monitoring_api::Config>,
pub slasher: Option<slasher::Config>,
pub logger_config: LoggerConfig,
}

impl Default for Config {
Expand All @@ -96,6 +97,7 @@ impl Default for Config {
slasher: None,
validator_monitor_auto: false,
validator_monitor_pubkeys: vec![],
logger_config: LoggerConfig::default(),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions lcli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -781,8 +781,8 @@ fn run<T: EthSpec>(
.map_err(|e| format!("should start tokio runtime: {:?}", e))?
.initialize_logger(LoggerConfig {
path: None,
debug_level: "trace",
logfile_debug_level: "trace",
debug_level: String::from("trace"),
logfile_debug_level: String::from("trace"),
log_format: None,
log_color: false,
disable_log_timestamp: false,
Expand Down
2 changes: 2 additions & 0 deletions lighthouse/environment/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ slog-async = "2.5.0"
futures = "0.3.7"
slog-json = "2.3.0"
exit-future = "0.2.0"
serde = "1.0.116"
serde_derive = "1.0.116"

[target.'cfg(not(target_family = "unix"))'.dependencies]
ctrlc = { version = "3.1.6", features = ["termination"] }
33 changes: 25 additions & 8 deletions lighthouse/environment/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use eth2_network_config::Eth2NetworkConfig;
use futures::channel::mpsc::{channel, Receiver, Sender};
use futures::{future, StreamExt};

use serde_derive::{Deserialize, Serialize};
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;
Expand Down Expand Up @@ -43,17 +44,33 @@ const MAXIMUM_SHUTDOWN_TIME: u64 = 15;
/// - `path` == None,
/// - `max_log_size` == 0,
/// - `max_log_number` == 0,
pub struct LoggerConfig<'a> {
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LoggerConfig {
pub path: Option<PathBuf>,
pub debug_level: &'a str,
pub logfile_debug_level: &'a str,
pub log_format: Option<&'a str>,
pub debug_level: String,
pub logfile_debug_level: String,
pub log_format: Option<String>,
pub log_color: bool,
pub disable_log_timestamp: bool,
pub max_log_size: u64,
pub max_log_number: usize,
pub compression: bool,
}
impl Default for LoggerConfig {
fn default() -> Self {
LoggerConfig {
path: None,
debug_level: String::from("info"),
logfile_debug_level: String::from("debug"),
log_format: None,
log_color: false,
disable_log_timestamp: false,
max_log_size: 200,
max_log_number: 5,
compression: false,
}
}
}

/// Builds an `Environment`.
pub struct EnvironmentBuilder<E: EthSpec> {
Expand Down Expand Up @@ -135,7 +152,7 @@ impl<E: EthSpec> EnvironmentBuilder<E> {
/// Note that background file logging will spawn a new thread.
pub fn initialize_logger(mut self, config: LoggerConfig) -> Result<Self, String> {
// Setting up the initial logger format and build it.
let stdout_drain = if let Some(format) = config.log_format {
let stdout_drain = if let Some(ref format) = config.log_format {
match format.to_uppercase().as_str() {
"JSON" => {
let stdout_drain = slog_json::Json::default(std::io::stdout()).fuse();
Expand Down Expand Up @@ -168,7 +185,7 @@ impl<E: EthSpec> EnvironmentBuilder<E> {
.build()
};

let stdout_drain = match config.debug_level {
let stdout_drain = match config.debug_level.as_str() {
"info" => stdout_drain.filter_level(Level::Info),
"debug" => stdout_drain.filter_level(Level::Debug),
"trace" => stdout_drain.filter_level(Level::Trace),
Expand Down Expand Up @@ -220,7 +237,7 @@ impl<E: EthSpec> EnvironmentBuilder<E> {
}
}

let logfile_level = match config.logfile_debug_level {
let logfile_level = match config.logfile_debug_level.as_str() {
"info" => Severity::Info,
"debug" => Severity::Debug,
"trace" => Severity::Trace,
Expand All @@ -233,7 +250,7 @@ impl<E: EthSpec> EnvironmentBuilder<E> {
let file_logger = FileLoggerBuilder::new(&path)
.level(logfile_level)
.channel_size(LOG_CHANNEL_SIZE)
.format(match config.log_format {
.format(match config.log_format.as_deref() {
Some("JSON") => Format::Json,
_ => Format::default(),
})
Expand Down
11 changes: 6 additions & 5 deletions lighthouse/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,17 +438,17 @@ fn run<E: EthSpec>(

let logger_config = LoggerConfig {
path: log_path,
debug_level,
logfile_debug_level,
log_format,
debug_level: String::from(debug_level),
logfile_debug_level: String::from(logfile_debug_level),
log_format: log_format.map(String::from),
log_color,
disable_log_timestamp,
max_log_size: logfile_max_size * 1_024 * 1_024,
max_log_number: logfile_max_number,
compression: logfile_compress,
};

let builder = environment_builder.initialize_logger(logger_config)?;
let builder = environment_builder.initialize_logger(logger_config.clone())?;

let mut environment = builder
.multi_threaded_tokio_runtime()?
Expand Down Expand Up @@ -528,7 +528,8 @@ fn run<E: EthSpec>(
let context = environment.core_context();
let log = context.log().clone();
let executor = context.executor.clone();
let config = beacon_node::get_config::<E>(matches, &context)?;
let mut config = beacon_node::get_config::<E>(matches, &context)?;
config.logger_config = logger_config;
let shutdown_flag = matches.is_present("immediate-shutdown");
// Dump configs if `dump-config` or `dump-chain-config` flags are set
clap_utils::check_dump_configs::<_, E>(matches, &config, &context.eth2_config.spec)?;
Expand Down
36 changes: 36 additions & 0 deletions lighthouse/tests/beacon_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1465,3 +1465,39 @@ fn monitoring_endpoint() {
assert_eq!(api_conf.update_period_secs, Some(30));
});
}

// Tests for Logger flags.
#[test]
fn default_log_color_flag() {
CommandLineTest::new()
.run_with_zero_port()
.with_config(|config| {
assert!(!config.logger_config.log_color);
});
}
#[test]
fn enabled_log_color_flag() {
CommandLineTest::new()
.flag("log-color", None)
.run_with_zero_port()
.with_config(|config| {
assert!(config.logger_config.log_color);
});
}
#[test]
fn default_disable_log_timestamp_flag() {
CommandLineTest::new()
.run_with_zero_port()
.with_config(|config| {
assert!(!config.logger_config.disable_log_timestamp);
});
}
#[test]
fn enabled_disable_log_timestamp_flag() {
CommandLineTest::new()
.flag("disable-log-timestamp", None)
.run_with_zero_port()
.with_config(|config| {
assert!(config.logger_config.disable_log_timestamp);
});
}
9 changes: 3 additions & 6 deletions testing/simulator/src/eth1_sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,12 @@ pub fn run_eth1_sim(matches: &ArgMatches) -> Result<(), String> {
})
.collect::<Vec<_>>();

let log_level = "debug";
let log_format = None;

let mut env = EnvironmentBuilder::minimal()
.initialize_logger(LoggerConfig {
path: None,
debug_level: log_level,
logfile_debug_level: "debug",
log_format,
debug_level: String::from("debug"),
logfile_debug_level: String::from("debug"),
log_format: None,
log_color: false,
disable_log_timestamp: false,
max_log_size: 0,
Expand Down
9 changes: 3 additions & 6 deletions testing/simulator/src/no_eth1_sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,12 @@ pub fn run_no_eth1_sim(matches: &ArgMatches) -> Result<(), String> {
})
.collect::<Vec<_>>();

let log_level = "debug";
let log_format = None;

let mut env = EnvironmentBuilder::mainnet()
.initialize_logger(LoggerConfig {
path: None,
debug_level: log_level,
logfile_debug_level: "debug",
log_format,
debug_level: String::from("debug"),
logfile_debug_level: String::from("debug"),
log_format: None,
log_color: false,
disable_log_timestamp: false,
max_log_size: 0,
Expand Down
6 changes: 3 additions & 3 deletions testing/simulator/src/sync_sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ fn syncing_sim(
let mut env = EnvironmentBuilder::minimal()
.initialize_logger(LoggerConfig {
path: None,
debug_level: log_level,
logfile_debug_level: "debug",
log_format,
debug_level: String::from(log_level),
logfile_debug_level: String::from("debug"),
log_format: log_format.map(String::from),
log_color: false,
disable_log_timestamp: false,
max_log_size: 0,
Expand Down