Skip to content
This repository was archived by the owner on Jan 11, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
a5117db
skip null round retry
Nov 14, 2023
43bf8fe
rearrange logging
Nov 14, 2023
d485555
Merge branch 'main' of protocol-github:consensus-shipyard/fendermint …
Nov 15, 2023
ed5ab9d
specify import
Nov 15, 2023
5796d5c
better null error handling
Nov 15, 2023
961b6be
format code
Nov 15, 2023
a205b2e
add tracing logs
Nov 15, 2023
b83dd8e
expand tilda
Nov 15, 2023
bba832b
prettier logging
Nov 15, 2023
3d11185
prettier logs
Nov 15, 2023
5a5c134
update logging
Nov 15, 2023
d6b0f0d
prettier log
Nov 15, 2023
9a585f1
Merge branch 'main' of protocol-github:consensus-shipyard/fendermint …
Nov 15, 2023
e4873a6
use ipc user instead of root
Nov 15, 2023
884a5a2
specify log path
Nov 15, 2023
c83dde3
remove unused logs
Nov 15, 2023
87445a6
Update fendermint/vm/topdown/src/finality/null.rs
cryptoAtwill Nov 15, 2023
2fa6c84
Update fendermint/vm/interpreter/src/chain.rs
cryptoAtwill Nov 15, 2023
6bb0bf0
Update fendermint/vm/topdown/src/sync.rs
cryptoAtwill Nov 15, 2023
ae9aed1
structured logging and log dir optional
Nov 15, 2023
8e73396
add debug logger
Nov 15, 2023
5d3113f
add debug logs
Nov 15, 2023
0e1bcc3
log fendermint only
Nov 15, 2023
f79f7f3
Look ahead limit use finalized height (#433)
cryptoAtwill Nov 15, 2023
7a9e257
comments
Nov 15, 2023
6810ed9
Merge branch 'tracing-logs' of protocol-github:consensus-shipyard/fen…
Nov 15, 2023
dde324d
Update fendermint/vm/topdown/src/sync.rs
cryptoAtwill Nov 15, 2023
636bdc5
rename makes everything clearer
Nov 15, 2023
d2d2fa8
Merge branch 'tracing-logs' of protocol-github:consensus-shipyard/fen…
Nov 15, 2023
0ba8f9c
Update fendermint/app/src/main.rs
cryptoAtwill Nov 15, 2023
46022c9
clean logs
Nov 15, 2023
2e374f0
Merge branch 'tracing-logs' of protocol-github:consensus-shipyard/fen…
Nov 15, 2023
bbbb8a5
log to console
Nov 15, 2023
6d94af3
update docker commands
Nov 15, 2023
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
137 changes: 113 additions & 24 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ tracing = "0.1"
tracing-subscriber = "0.3"
url = "2.4.1"
zeroize = "1.6"
trace4rs = "0.5.1"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you know if this is available on Github somewhere? I can't find a link at https://crates.io/crates/trace4rs

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

literally = "0.1.3"

# Vendored for cross-compilation, see https://github.com/cross-rs/cross/wiki/Recipes#openssl
openssl = { version = "0.10", features = ["vendored"] }
Expand Down
2 changes: 2 additions & 0 deletions fendermint/app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ tokio = { workspace = true }
tower-abci = { workspace = true }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }
trace4rs = { workspace = true }
literally = { workspace = true }

fendermint_abci = { path = "../abci" }
fendermint_app_options = { path = "./options" }
Expand Down
4 changes: 4 additions & 0 deletions fendermint/app/options/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ pub struct Options {
)]
pub home_dir: PathBuf,

/// Set a custom directory for ipc log files.
#[arg(short = 'l', long, env = "FM_LOG_DIR")]
pub log_dir: Option<PathBuf>,

/// Optionally override the default configuration.
#[arg(short, long, default_value = "dev")]
pub mode: String,
Expand Down
106 changes: 96 additions & 10 deletions fendermint/app/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
// Copyright 2022-2023 Protocol Labs
// SPDX-License-Identifier: Apache-2.0, MIT

use tracing_subscriber::FmtSubscriber;
use anyhow::{anyhow, Context};
use std::path::PathBuf;
use std::str::FromStr;
use std::sync::Arc;
use trace4rs::config::{AppenderId, Policy, Target};
use trace4rs::{
config::{self, Config, Format},
Handle,
};

pub use fendermint_app_options as options;
pub use fendermint_app_settings as settings;
use fendermint_app_settings::expand_tilde;

mod cmd;

#[tokio::main]
async fn main() {
let opts = options::parse();

// Log events to stdout.
if let Some(level) = opts.tracing_level() {
// Writing to stderr so if we have output like JSON then we can pipe it to something else.
let subscriber = FmtSubscriber::builder()
.with_max_level(level)
.with_writer(std::io::stderr)
.finish();

tracing::subscriber::set_global_default(subscriber)
.expect("setting default subscriber failed");
create_log(level, opts.log_dir.as_ref()).expect("cannot create logging");
}

if let Err(e) = cmd::exec(&opts).await {
Expand All @@ -30,6 +31,91 @@ async fn main() {
}
}

fn create_log(level: tracing::Level, log_dir: Option<&PathBuf>) -> anyhow::Result<()> {
let console_appender = config::Appender::Console;

// default logging output info log to console
let default = config::Logger {
level: config::LevelFilter::from_str(level.as_str())?,
appenders: literally::hset! { AppenderId::from("console") },
format: Format::default(),
};

let mut config = Config {
default,
loggers: literally::hmap! {},
appenders: literally::hmap! {AppenderId::from("console") => console_appender},
};

if let Some(log_dir) = log_dir {
let log_folder = expand_tilde(log_dir)
.to_str()
.ok_or_else(|| anyhow!("cannot parse log folder"))?
.to_string();
std::fs::create_dir_all(&log_folder).context("cannot create log folder")?;

let topdown_appender = config::Appender::RollingFile {
path: format!("{log_folder}/topdown.log"),
policy: Policy {
maximum_file_size: "10mb".to_string(),
// we keep the last 5 log files, older files will be deleted
max_size_roll_backups: 5,
pattern: None,
},
};
let debug_appender = config::Appender::RollingFile {
path: format!("{log_folder}/debug.log"),
policy: Policy {
maximum_file_size: "10mb".to_string(),
// we keep the last 5 log files, older files will be deleted
max_size_roll_backups: 5,
pattern: None,
},
};

let topdown_logger = config::Logger {
level: config::LevelFilter::DEBUG,
appenders: literally::hset! { AppenderId::from("topdown") },
format: Format::default(),
};
let debug_logger = config::Logger {
level: config::LevelFilter::DEBUG,
appenders: literally::hset! { AppenderId::from("debug") },
format: Format::default(),
};

config.loggers.insert(
Target::from("fendermint_vm_topdown"),
topdown_logger.clone(),
);
config.loggers.insert(
Target::from("fendermint_vm_interpreter::chain"),
topdown_logger,
);
config
.appenders
.insert(AppenderId::from("topdown"), topdown_appender);
Comment on lines +95 to +97
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why do we need to insert the logger into the config, when it's already set in the topdown_logger?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I havent looked very deep into trace4rs, my guess is when an event is emitted, it checks if there are any Target watching this event, then target has a logger, and logger has an appender.


// maybe there are better ways to handle this, but * does not seem to be supported
config
.loggers
.insert(Target::from("fendermint_app"), debug_logger.clone());
config
.loggers
.insert(Target::from("fendermint_vm_interpreter"), debug_logger);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

https://docs.rs/trace4rs/0.5.1/src/trace4rs/handle/loggers.rs.html#91 suggests that a simple Target::from("fendermint") should work.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

funny thing is, with this, all logs are directly to debug and console is empty

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe because it's set as a "default" which could mean "if nothing else matched"? Perhaps insert it explicitly with the "" target?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

config
.appenders
.insert(AppenderId::from("debug"), debug_appender);
Copy link
Copy Markdown
Contributor

@aakoshh aakoshh Nov 15, 2023

Choose a reason for hiding this comment

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

Yeah so why don't we insert a clone of the default console logger with an Target::from("") and the INFO level?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yeah, but it seems to me this is a bug or sth, we should not be able to do that though. But I added this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What's a bug? Why shouldn't we be able to set a logger that captures everything and logs to the console if we want to?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I mean we need to do this:

        config
            .loggers
            .insert(Target::from("fendermint"), debug_logger);
        config.loggers.insert(Target::from("fendermint"), default);

but ideally we should not need config.loggers.insert(Target::from("fendermint"), default); as we already set default.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah, okay, so if fendermint* will go to both debug files and console, and everything else will also go to the console because it matches all namespaces, if their log level is at least the selected one 👍

}

let handle = Arc::new(Handle::try_from(config).unwrap());

tracing::subscriber::set_global_default(handle.subscriber())
.context("setting default subscriber failed")?;

Ok(())
}

#[cfg(test)]
mod tests {
use cid::Cid;
Expand Down
Loading