mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-16 20:39:10 +00:00
Move account manager under main binary (#601)
* Move account_manager under `lighthouse` binary * Unify logfile handling in `environment` crate.
This commit is contained in:
@@ -18,3 +18,4 @@ slog-async = "^2.3.0"
|
||||
environment = { path = "./environment" }
|
||||
futures = "0.1.25"
|
||||
validator_client = { "path" = "../validator_client" }
|
||||
account_manager = { "path" = "../account_manager" }
|
||||
|
||||
@@ -17,3 +17,4 @@ slog-async = "^2.3.0"
|
||||
ctrlc = { version = "3.1.1", features = ["termination"] }
|
||||
futures = "0.1.25"
|
||||
parking_lot = "0.7"
|
||||
slog-json = "2.3.0"
|
||||
|
||||
@@ -9,9 +9,12 @@
|
||||
|
||||
use eth2_config::Eth2Config;
|
||||
use futures::{sync::oneshot, Future};
|
||||
use slog::{o, Drain, Level, Logger};
|
||||
use slog::{info, o, Drain, Level, Logger};
|
||||
use sloggers::{null::NullLoggerBuilder, Build};
|
||||
use std::cell::RefCell;
|
||||
use std::fs::OpenOptions;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Mutex;
|
||||
use tokio::runtime::{Builder as RuntimeBuilder, Runtime, TaskExecutor};
|
||||
use types::{EthSpec, InteropEthSpec, MainnetEthSpec, MinimalEthSpec};
|
||||
|
||||
@@ -224,6 +227,28 @@ impl<E: EthSpec> Environment<E> {
|
||||
.map_err(|e| format!("Tokio runtime shutdown returned an error: {:?}", e))
|
||||
}
|
||||
|
||||
/// Sets the logger (and all child loggers) to log to a file.
|
||||
pub fn log_to_json_file(&mut self, path: PathBuf) -> Result<(), String> {
|
||||
let file = OpenOptions::new()
|
||||
.create(true)
|
||||
.write(true)
|
||||
.truncate(true)
|
||||
.open(&path)
|
||||
.map_err(|e| format!("Unable to open logfile: {:?}", e))?;
|
||||
|
||||
let drain = Mutex::new(slog_json::Json::default(file)).fuse();
|
||||
let drain = slog_async::Async::new(drain).build().fuse();
|
||||
self.log = slog::Logger::root(drain, o!());
|
||||
|
||||
info!(
|
||||
self.log,
|
||||
"Logging to JSON file";
|
||||
"path" => format!("{:?}", path)
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn eth_spec_instance(&self) -> &E {
|
||||
&self.eth_spec_instance
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ use clap::{App, Arg, ArgMatches};
|
||||
use env_logger::{Builder, Env};
|
||||
use environment::EnvironmentBuilder;
|
||||
use slog::{crit, info, warn};
|
||||
use std::path::PathBuf;
|
||||
use std::process::exit;
|
||||
use types::EthSpec;
|
||||
use validator_client::ProductionValidatorClient;
|
||||
@@ -52,6 +53,7 @@ fn main() {
|
||||
)
|
||||
.subcommand(beacon_node::cli_app())
|
||||
.subcommand(validator_client::cli_app())
|
||||
.subcommand(account_manager::cli_app())
|
||||
.get_matches();
|
||||
|
||||
macro_rules! run_with_spec {
|
||||
@@ -92,6 +94,13 @@ fn run<E: EthSpec>(
|
||||
|
||||
let log = environment.core_context().log;
|
||||
|
||||
if let Some(log_path) = matches.value_of("logfile") {
|
||||
let path = log_path
|
||||
.parse::<PathBuf>()
|
||||
.map_err(|e| format!("Failed to parse log path: {:?}", e))?;
|
||||
environment.log_to_json_file(path)?;
|
||||
}
|
||||
|
||||
if std::mem::size_of::<usize>() != 8 {
|
||||
crit!(
|
||||
log,
|
||||
@@ -114,6 +123,16 @@ fn run<E: EthSpec>(
|
||||
//
|
||||
// Creating a command which can run both might be useful future works.
|
||||
|
||||
if let Some(sub_matches) = matches.subcommand_matches("Account Manager") {
|
||||
let runtime_context = environment.core_context();
|
||||
|
||||
account_manager::run(sub_matches, runtime_context);
|
||||
|
||||
// Exit early if the account manager was run. It does not used the tokio executor, so no
|
||||
// need to wait for it to shutdown.
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let beacon_node = if let Some(sub_matches) = matches.subcommand_matches("Beacon Node") {
|
||||
let runtime_context = environment.core_context();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user