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

Use Config File to Drive Components Log Configuration #1851

Merged
merged 46 commits into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
2cd2576
most chaneges
tyshko5 Aug 23, 2022
f89b76d
fix lint
tyshko5 Aug 23, 2022
dd49501
requested changes
tyshko5 Aug 24, 2022
d4ee99d
fix
tyshko5 Aug 24, 2022
88240e7
requested changes
tyshko5 Aug 24, 2022
02077de
comment
tyshko5 Aug 24, 2022
3b85394
fix comments
tyshko5 Aug 24, 2022
2ca8590
delete option
tyshko5 Aug 24, 2022
cacd86b
requested changes
tyshko5 Aug 31, 2022
1082504
Add `--halt-after-import` flag to CLI (#1835)
connormullett Aug 23, 2022
9915dfa
Enable spellcheck for `ipld/` (#1822)
connormullett Aug 24, 2022
a90b9a6
spellcheck changes for vm/interpreter (#1844)
jdjaustin Aug 24, 2022
9fd850d
Implement cargo spellcheck for vm/actor_interface (#1843)
jdjaustin Aug 24, 2022
17c3c06
Cleanly shutdown all tasks and make sure RocksDB is closed properly (…
elmattic Aug 25, 2022
e24cb31
Run `cargo spellcheck` over every internal crate (#1853)
lemmih Aug 29, 2022
a1de5b2
Improve the naming of exported snapshots. (#1771)
tyshko5 Aug 30, 2022
f19770a
Add the output fields of wallet list subcommand (#1785)
jimluo Sep 1, 2022
35d6496
Define each word in the custom forest.dic dictionary (#1857)
tyshko5 Sep 1, 2022
06df807
Add CI step to check for dead links in documentation book (#1860)
lemmih Sep 1, 2022
2f57416
Fix access level for CHAIN_GET_NAME. (#1866)
lemmih Sep 1, 2022
74a9bce
Change Proposer to return a vector of tasks. (#1865)
aakoshh Sep 1, 2022
acd23b9
Start RPC server before loading snapshot (#1831)
connormullett Sep 2, 2022
5db55e1
rubify sync check, add logs as attachments (#1867)
LesnyRumcajs Sep 2, 2022
aff261b
Validate the ChainConfig struct at construction time (#1845)
tyshko5 Sep 2, 2022
92bdebd
Explicitly import the lazy_static macro. (#1872)
tyshko5 Sep 5, 2022
1e3e87d
Use constant data instead of lazy_static in forest_networks (#1876)
tyshko5 Sep 6, 2022
3ce45da
Daemonize Forest node (#1856)
elmattic Sep 7, 2022
06bc6f6
fix after merge
tyshko5 Sep 7, 2022
5c616fe
Add `--halt-after-import` flag to CLI (#1835)
connormullett Aug 23, 2022
582d488
Enable spellcheck for `ipld/` (#1822)
connormullett Aug 24, 2022
144cf7f
spellcheck changes for vm/interpreter (#1844)
jdjaustin Aug 24, 2022
fb7ee95
Implement cargo spellcheck for vm/actor_interface (#1843)
jdjaustin Aug 24, 2022
52bccb8
Cleanly shutdown all tasks and make sure RocksDB is closed properly (…
elmattic Aug 25, 2022
17b8fe7
Run `cargo spellcheck` over every internal crate (#1853)
lemmih Aug 29, 2022
4373808
Improve the naming of exported snapshots. (#1771)
tyshko5 Aug 30, 2022
47f0298
Change Proposer to return a vector of tasks. (#1865)
aakoshh Sep 1, 2022
b16917d
Start RPC server before loading snapshot (#1831)
connormullett Sep 2, 2022
6501d51
Validate the ChainConfig struct at construction time (#1845)
tyshko5 Sep 2, 2022
54187d9
Explicitly import the lazy_static macro. (#1872)
tyshko5 Sep 5, 2022
1b7dcfe
Use constant data instead of lazy_static in forest_networks (#1876)
tyshko5 Sep 6, 2022
2632809
Daemonize Forest node (#1856)
elmattic Sep 7, 2022
ce2d57b
Merge branch 'main' into tyshko5/issue-1520
tyshko5 Sep 7, 2022
f2def15
Merge branch 'main' into tyshko5/issue-1520
tyshko5 Sep 7, 2022
6e8907a
fix after rebase-merge activity
tyshko5 Sep 7, 2022
6525507
fix forest dic
tyshko5 Sep 7, 2022
3c9aaa1
redundunt dic
tyshko5 Sep 7, 2022
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
14 changes: 14 additions & 0 deletions forest/src/cli/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,23 @@ use forest_chain_sync::SyncConfig;
use forest_libp2p::Libp2pConfig;
use forest_networks::ChainConfig;
use serde::{Deserialize, Serialize};
use std::collections::HashSet;
use std::path::PathBuf;
use std::sync::Arc;

use super::client::Client;

#[derive(Serialize, Deserialize, Default, PartialEq)]
pub struct LogConfig {
pub log_values: HashSet<LogValue>,
}

#[derive(Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct LogValue {
pub module: String,
pub level: String,
elmattic marked this conversation as resolved.
Show resolved Hide resolved
}

/// Structure that defines daemon configuration when process is detached
#[derive(Deserialize, Serialize, PartialEq)]
pub struct DaemonConfig {
Expand Down Expand Up @@ -45,6 +57,7 @@ pub struct Config {
pub sync: SyncConfig,
pub chain: Arc<ChainConfig>,
pub daemon: DaemonConfig,
pub log: LogConfig,
}

#[cfg(test)]
Expand Down Expand Up @@ -77,6 +90,7 @@ mod test {
sync: val.sync,
chain: Arc::new(ChainConfig::default()),
daemon: DaemonConfig::default(),
log: Default::default(),
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions forest/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ pub(super) use self::chain_cmd::ChainCommands;
pub use self::client::Client;
pub use self::config::Config;
pub use self::config::DaemonConfig;
pub use self::config::LogConfig;
pub use self::config::LogValue;
pub(super) use self::fetch_params_cmd::FetchCommands;
pub(super) use self::genesis_cmd::GenesisCommands;
pub(super) use self::mpool_cmd::MpoolCommands;
Expand Down Expand Up @@ -183,6 +185,13 @@ pub struct CliOpts {
/// Daemonize Forest process
#[structopt(long)]
pub detach: bool,
// env_logger-0.7 can only redirect to stderr or stdout. Version 0.9 can redirect to a file.
// However, we cannot upgrade to version 0.9 because pretty_env_logger depends on version 0.7
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use pretty-env-logger from Github repo not crates.io, or am I missing something?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is an option. I have no strong opinions about whether we do this now or hold off until later when a release is out.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we hold off, let's create a separate issue and get rid of the commented out code (and copy the snippet into the issue).

// and hasn't been updated in quite a while. See https://github.com/seanmonstar/pretty-env-logger/issues/52
// #[structopt(
// help = "Specify a filename into which logging should be appended"
// )]
// pub log_file: Option<PathBuf>,
}

impl CliOpts {
Expand Down
11 changes: 10 additions & 1 deletion forest/src/logger/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
// Copyright 2019-2022 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0, MIT

use crate::cli::LogConfig;
use crate::cli_error_and_die;
use log::LevelFilter;
use std::str::FromStr;

pub(crate) fn setup_logger() {
pub(crate) fn setup_logger(log_config: &LogConfig) {
let mut logger_builder = pretty_env_logger::formatted_timed_builder();

// Assign default log level settings
Expand All @@ -20,6 +23,12 @@ pub(crate) fn setup_logger() {
logger_builder.filter(Some("rpc"), LevelFilter::Info);
logger_builder.filter(None, LevelFilter::Info);

for item in &log_config.log_values {
let level = LevelFilter::from_str(item.level.as_str())
.unwrap_or_else(|_| cli_error_and_die("could not parse LevelFilter enum value", 1));
logger_builder.filter(Some(item.module.as_str()), level);
}

// Override log level based on filters if set
if let Ok(s) = ::std::env::var("RUST_LOG") {
logger_builder.parse_filters(&s);
Expand Down
57 changes: 32 additions & 25 deletions forest/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,40 +91,47 @@ fn build_daemon<'a>(config: &DaemonConfig) -> anyhow::Result<Daemon<'a>> {
}

fn main() {
logger::setup_logger();
lemmih marked this conversation as resolved.
Show resolved Hide resolved

// Capture Cli inputs
let Cli { opts, cmd } = Cli::from_args();

// Run forest as a daemon if no other subcommands are used. Otherwise, run the subcommand.
match opts.to_config() {
Ok(cfg) => match cmd {
Some(command) => {
task::block_on(subcommand::process(command, cfg));
}
None => {
if opts.detach {
create_ipc_lock();
info!(
"Redirecting stdout and stderr to files {} and {}.",
cfg.daemon.stdout.display(),
cfg.daemon.stderr.display()
);
let result = build_daemon(&cfg.daemon)
.unwrap_or_else(|e| {
cli_error_and_die(format!("Error building daemon. Error was: {e}"), 1)
})
.start();
match result {
Ok(_) => info!("Process detached"),
Err(e) => {
cli_error_and_die(format!("Error when detaching. Error was: {e}"), 1);
Ok(cfg) => {
logger::setup_logger(&cfg.log);
match cmd {
Some(command) => {
task::block_on(subcommand::process(command, cfg));
}
None => {
if opts.detach {
create_ipc_lock();
info!(
"Redirecting stdout and stderr to files {} and {}.",
cfg.daemon.stdout.display(),
cfg.daemon.stderr.display()
);
let result = build_daemon(&cfg.daemon)
.unwrap_or_else(|e| {
cli_error_and_die(
format!("Error building daemon. Error was: {e}"),
1,
)
})
.start();
match result {
Ok(_) => info!("Process detached"),
Err(e) => {
cli_error_and_die(
format!("Error when detaching. Error was: {e}"),
1,
);
}
}
}
task::block_on(daemon::start(cfg, opts.detach));
}
task::block_on(daemon::start(cfg, opts.detach));
}
},
}
Err(e) => {
cli_error_and_die(format!("Error parsing config. Error was: {e}"), 1);
}
Expand Down