This repository was archived by the owner on Jan 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Tracing logs #432
Merged
Merged
Tracing logs #432
Changes from 15 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
a5117db
skip null round retry
43bf8fe
rearrange logging
d485555
Merge branch 'main' of protocol-github:consensus-shipyard/fendermint …
ed5ab9d
specify import
5796d5c
better null error handling
961b6be
format code
a205b2e
add tracing logs
b83dd8e
expand tilda
bba832b
prettier logging
3d11185
prettier logs
5a5c134
update logging
d6b0f0d
prettier log
9a585f1
Merge branch 'main' of protocol-github:consensus-shipyard/fendermint …
e4873a6
use ipc user instead of root
884a5a2
specify log path
c83dde3
remove unused logs
87445a6
Update fendermint/vm/topdown/src/finality/null.rs
cryptoAtwill 2fa6c84
Update fendermint/vm/interpreter/src/chain.rs
cryptoAtwill 6bb0bf0
Update fendermint/vm/topdown/src/sync.rs
cryptoAtwill ae9aed1
structured logging and log dir optional
8e73396
add debug logger
5d3113f
add debug logs
0e1bcc3
log fendermint only
f79f7f3
Look ahead limit use finalized height (#433)
cryptoAtwill 7a9e257
comments
6810ed9
Merge branch 'tracing-logs' of protocol-github:consensus-shipyard/fen…
dde324d
Update fendermint/vm/topdown/src/sync.rs
cryptoAtwill 636bdc5
rename makes everything clearer
d2d2fa8
Merge branch 'tracing-logs' of protocol-github:consensus-shipyard/fen…
0ba8f9c
Update fendermint/app/src/main.rs
cryptoAtwill 46022c9
clean logs
2e374f0
Merge branch 'tracing-logs' of protocol-github:consensus-shipyard/fen…
bbbb8a5
log to console
6d94af3
update docker commands
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,19 @@ | ||
| // Copyright 2022-2023 Protocol Labs | ||
| // SPDX-License-Identifier: Apache-2.0, MIT | ||
|
|
||
| use tracing_subscriber::FmtSubscriber; | ||
| use anyhow::{anyhow, Context}; | ||
| use std::path::Path; | ||
| 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; | ||
|
|
||
|
|
@@ -14,14 +23,7 @@ async fn main() { | |
|
|
||
| // Log events to stdout. | ||
aakoshh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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).expect("cannot create logging"); | ||
| } | ||
|
|
||
| if let Err(e) = cmd::exec(&opts).await { | ||
|
|
@@ -30,6 +32,58 @@ async fn main() { | |
| } | ||
| } | ||
|
|
||
| fn create_log(level: tracing::Level, log_dir: &Path) -> anyhow::Result<()> { | ||
| 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 console_appender = config::Appender::Console; | ||
| 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, | ||
| }, | ||
| }; | ||
|
|
||
| // debug level logger | ||
| let topdown_logger = config::Logger { | ||
| level: config::LevelFilter::DEBUG, | ||
|
||
| appenders: literally::hset! { AppenderId::from("topdown") }, | ||
| format: Format::default(), | ||
| }; | ||
|
|
||
| // 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 config = Config { | ||
| default, | ||
| loggers: literally::hmap! { | ||
| Target::from("fendermint_vm_topdown") => topdown_logger.clone(), | ||
| Target::from("fendermint_vm_interpreter::chain") => topdown_logger, | ||
aakoshh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }, | ||
| appenders: literally::hmap! { | ||
| AppenderId::from("console") => console_appender, | ||
| AppenderId::from("topdown") => topdown_appender | ||
aakoshh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }, | ||
| }; | ||
|
|
||
| let handle = Arc::new(Handle::try_from(config).unwrap()); | ||
cryptoAtwill marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| tracing::subscriber::set_global_default(handle.subscriber()) | ||
| .context("setting default subscriber failed")?; | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use cid::Cid; | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/imperva/trace4rs