h3poteto / megalodon-rs

Fediverse API client library for Rust
Apache License 2.0
108 stars 22 forks source link

Use tracing instead of log #206

Closed joshka closed 6 months ago

joshka commented 6 months ago

Before:

image

After:

image
h3poteto commented 6 months ago

Why did you use tracing instead of log?

joshka commented 6 months ago

Why did you use tracing instead of log?

I'd like to add more more instrumentation to the methods to make it easy to build out a tui for mastodon (https://github.com/joshka/tooters). The approach in tracing crate is better for this than log crate. E.g. the #[instrument] attribute, and the ability to log values as the value and not just as a text string (log does have the kv feature, but it's more difficult to support and not as powerful as the values approach). Filtering specific logs and directing them is also easier in tracing. Tracing makes it possible to more easily see which network calls are part of which operation using the concept of spans around groups of calls.

Tracing can be configured to send events to to log (and also the reverse), so there's no real downside to this and a bunch of upside.

h3poteto commented 6 months ago

OK, thanks.