Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: store logs in different folders based on the chain #3948

Merged
merged 6 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
45 changes: 43 additions & 2 deletions bin/reth/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
//! CLI definition and entrypoint to executable
use crate::{
args::utils::genesis_value_parser,
chain, config, db, debug_cmd,
dirs::{LogsDir, PlatformPath},
dirs::{DataDirPath, LogsDir, MaybePlatformPath, PlatformPath},
node, p2p,
runner::CliRunner,
stage, test_vectors,
Expand All @@ -14,9 +15,20 @@ use reth_tracing::{
BoxedLayer, FileWorkerGuard,
};

use reth_primitives::ChainSpec;
use std::sync::Arc;

/// Parse CLI options, set up logging and run the chosen command.
pub fn run() -> eyre::Result<()> {
let opt = Cli::parse();
let mut opt = Cli::parse();

if opt.datadir.is_some() {
// move logs to the already-chain-specific --datadir
opt.logs.log_directory = opt.datadir.unwrap_or_default().map_to::<LogsDir>();
} else {
// add network name to logs dir
opt.logs.log_directory = opt.logs.log_directory.join(opt.chain.chain.to_string());
alessandromazza98 marked this conversation as resolved.
Show resolved Hide resolved
}

let mut layers = vec![reth_tracing::stdout(opt.verbosity.directive())];
let _guard = opt.logs.layer()?.map(|(layer, guard)| {
Expand Down Expand Up @@ -80,6 +92,35 @@ struct Cli {
#[clap(subcommand)]
command: Commands,

/// The chain this node is running.
///
/// Possible values are either a built-in chain or the path to a chain specification file.
///
/// Built-in chains:
/// - mainnet
/// - goerli
/// - sepolia
#[arg(
long,
value_name = "CHAIN_OR_PATH",
global = true,
verbatim_doc_comment,
default_value = "mainnet",
value_parser = genesis_value_parser,
global = true,
)]
chain: Arc<ChainSpec>,

/// The path to the data dir for all reth files and subdirectories.
///
/// Defaults to the OS-specific data directory:
///
/// - Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
/// - Windows: `{FOLDERID_RoamingAppData}/reth/`
/// - macOS: `$HOME/Library/Application Support/reth/`
#[arg(long, value_name = "DATA_DIR", global = true, verbatim_doc_comment, default_value_t)]
datadir: MaybePlatformPath<DataDirPath>,
alessandromazza98 marked this conversation as resolved.
Show resolved Hide resolved

#[clap(flatten)]
logs: Logs,

Expand Down
5 changes: 5 additions & 0 deletions bin/reth/src/dirs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ impl<D> PlatformPath<D> {
let platform_path = PlatformPath::<D>(path, std::marker::PhantomData);
ChainPath::new(platform_path, chain)
}

/// Map the inner path to a new type `T`.
pub fn map_to<T>(&self) -> PlatformPath<T> {
PlatformPath(self.0.clone(), std::marker::PhantomData)
}
}

/// An Optional wrapper type around [PlatformPath].
Expand Down