Skip to content

Commit

Permalink
add default location for bn,vc logfile
Browse files Browse the repository at this point in the history
  • Loading branch information
ThreeHrSleep committed Oct 26, 2024
1 parent b01aaff commit 938f173
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
1 change: 1 addition & 0 deletions beacon_node/beacon_chain/src/canonical_head.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ use store::{iter::StateRootsIterator, KeyValueStoreOp, StoreItem};
use task_executor::{JoinHandle, ShutdownReason};
use tracing::{debug, error, info, warn};
use types::*;

/// Simple wrapper around `RwLock` that uses private visibility to prevent any other modules from
/// accessing the contained lock without it being explicitly noted in this module.
pub struct CanonicalHeadRwLock<T>(RwLock<T>);
Expand Down
1 change: 0 additions & 1 deletion common/logging/src/sse_logging_components.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! This module provides an implementation of `slog::Drain` that optionally writes to a channel if
//! there are subscribers to a HTTP SSE stream.
use once_cell::sync::Lazy;
use serde_json;
use serde_json::json;
use serde_json::Value;
Expand Down
9 changes: 7 additions & 2 deletions lighthouse/environment/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,22 +174,27 @@ impl<E: EthSpec> EnvironmentBuilder<E> {
pub fn init_tracing(
mut self,
config: LoggerConfig,
logfile_prefix: &str,
) -> (
Self,
LoggingLayer,
LoggingLayer,
Option<SSELoggingComponents>,
) {
let filename_prefix = match logfile_prefix {
"beacon_node" => "beacon",
"validator_client" => "validator",
_ => logfile_prefix,
};
let file_logging_layer = if let Some(path) = config.path {
match RollingFileAppender::builder()
.rotation(Rotation::DAILY)
.max_log_files(config.max_log_number)
.filename_prefix("beacon")
.filename_prefix(filename_prefix)
.filename_suffix("log")
.build(path.clone())
{
Ok(file_appender) => {
info!(?path, "Logging to file");
let (file_non_blocking_writer, file_guard) =
tracing_appender::non_blocking(file_appender);

Expand Down
28 changes: 26 additions & 2 deletions lighthouse/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,26 @@ fn run<E: EthSpec>(
let logfile_restricted = !matches.get_flag("logfile-no-restricted-perms");

// Construct the path to the log file.
let log_path: Option<PathBuf> = clap_utils::parse_optional(matches, "logfile")?;
let mut log_path: Option<PathBuf> = clap_utils::parse_optional(matches, "logfile")?;
if log_path.is_none() {
log_path = match matches.subcommand() {
Some(("beacon_node", _)) => Some(
parse_path_or_default(matches, "datadir")?
.join(DEFAULT_BEACON_NODE_DIR)
.join("logs"),
),
Some(("validator_client", vc_matches)) => {
let base_path = if vc_matches.contains_id("validators-dir") {
parse_path_or_default(vc_matches, "validators-dir")?
} else {
parse_path_or_default(matches, "datadir")?.join(DEFAULT_VALIDATOR_DIR)
};

Some(base_path.join("logs"))
}
_ => None,
};
}

let sse_logging = {
if let Some(bn_matches) = matches.subcommand_matches("beacon_node") {
Expand Down Expand Up @@ -569,8 +588,13 @@ fn run<E: EthSpec>(
.with_writer(discv5_non_blocking_writer)
.with_line_number(true);

let logfile_prefix = match matches.subcommand_name() {
Some(subcommand) => subcommand,
None => "lighthouse",
};

let (builder, file_logging_layer, stdout_logging_layer, sse_logging_layer_opt) =
environment_builder.init_tracing(logger_config.clone());
environment_builder.init_tracing(logger_config.clone(), logfile_prefix);

let filter_layer = EnvFilter::try_from_default_env()
.or_else(|_| EnvFilter::try_new(logger_config.debug_level.to_lowercase().as_str()))
Expand Down

0 comments on commit 938f173

Please sign in to comment.