Conversation
Add tracing, initialize a subscriber, log a single event 'tracing initialized'.
Use tracing library for all log events. This is simply a matter of replacing logging calls that use `log::foo` with `tracing::foo`.
We can convert all upstream logging events to use tracing and be available for the default subscriber simply by using the line LogTracer::init()?; Connect upstream libraries to tracing using LogTracer.
Convert the current logging configuration to configure tracing instead.
Now we have tracing convert the `libp2p-comit` crate to use it.
Are you sure the changelog does not need updating? |
Clippy is emitting warnings that the cognitive complexity is to high. Refactor the error variants into a separate function. This actually does not clear the warning but the code is cleaner anyways. Add an attribute to quieten Clippy to the newly created function.
cnd/src/trace.rs
Outdated
|
||
fn level_from_level_filter(level: LevelFilter) -> Level { | ||
match level { | ||
LevelFilter::Off => Level::ERROR, |
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.
Why are we not respecting off
? Could just not initialize anything?
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.
Good idea, will implement.
cnd/src/main.rs
Outdated
let base_log_level = settings.logging.level; | ||
logging::initialize(base_log_level, settings.logging.structured)?; | ||
// We still want upstream library log messages, just only at Info level. | ||
LogTracer::init_with_filter(LevelFilter::Info)?; |
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.
I would see this as part of the initialization, no?
Why add this level of detail to main
?
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.
Good point, thanks. Implemented.
Tracing library at some times causes Clippy to emit a cognitive complexity warning. Issue raised on the tokio-rs/tracing repo tokio-rs/tracing#553 Add Clippy attributes to allow cognitive complexity where needed.
Some of the initialization is in main still, do it all within the init function. While we are at it, lets respect `LevelFilter::Off` to allow tracing to be turned off.
bors r+ |
1957: 1892 tracing r=tcharding a=tcharding Convert code base to use tokio-rs tracing library. With this applied (after running btc_eth/happy e2e test): ``` Jan 29 14:12:50.122 INFO cnd::trace: Initialized tracing with level: TRACE Jan 29 14:12:50.122 INFO cnd::seed: RootSeed file parent directory does not exist, creating recursively: /tmp/tmp-125556e02qp5UNTGu/seed.pem Jan 29 14:12:50.122 INFO cnd::seed: No seed file found, creating at: /tmp/tmp-125556e02qp5UNTGu/seed.pem Jan 29 14:12:50.288 INFO cnd::db: SQLite database file: /tmp/tmp-125556e02qp5UNTGu/cnd.sqlite Jan 29 14:12:50.290 INFO cnd::network: Starting with peer_id: QmafYkp7uHUj3FghWAbPZDbRTEFtJRdH3nQF5kXBYdXQYt Jan 29 14:12:50.293 DEBUG cnd::load_swaps: loading swaps from database ... Jan 29 14:12:50.295 INFO cnd: Starting HTTP server on 0.0.0.0:42789 Jan 29 14:12:53.583 TRACE cnd::http_api::routes::rfc003::handlers::post_swap: initiating new request: 932784b5-8ed9-47c1-8219-f216a9e0a017 Jan 29 14:12:53.589 INFO http: 127.0.0.1:39774 "POST /swaps/rfc003 HTTP/1.1" 201 "-" "axios/0.19.0" 39.353322ms Jan 29 14:12:53.589 DEBUG cnd::network: Making swap request to QmQskR8UngQvXfHrvrubAACkhQNVo4D2dPowjW81hWUxSu@/ip4/127.0.0.1/tcp/33085: SwapId(932784b5-8ed9-47c1-8219-f216a9e0a017) ``` And we get the same total number of log lines from running btc_eth/happy e2e test as before. Fixes: #1892 Co-authored-by: Tobin C. Harding <tobin.harding@coblox.tech>
bors r+ |
Already running a review |
Build succeeded |
Convert code base to use tokio-rs tracing library. With this applied (after running btc_eth/happy e2e test):
And we get the same total number of log lines from running btc_eth/happy e2e test as before.
Fixes: #1892