use tracing::info;
fn main() {
let number = 42;
info!("Running Main", number, value = 7);
println!("Hello, world!");
}
but this results in a compile error:
--> src/main.rs:5:27
|
5 | info!("Running Main", number, value = 7);
| -------------- ^^^^^^ ^ named argument never used
| | |
| | argument never used
| multiple missing formatting specifiers
error: could not compile `testtracing` due to previous error
I considered submitting a bug on github, but I feel that it's unlikely the core functionality of a very popular rust library would be broken, so I assume I am doing something obviously wrong here? Thanks!
I'm not familiar with tracing yet, but this sentence from the documentation seems relevant:
Finally, events may also include human-readable messages, in the form of a format string and (optional) arguments, after the event’s key-value fields.
So, you need to either use the values as format arguments (put {}s in the string), or put the values before the string to use them as key-value fields. Which one to do depends on what you want logged.
Ah you are totally correct @Yandros, the arguments go before the message for event! macros. Quite surprising since the tracing span! macro is exactly the opposite, where you do span!(Level::TRACE, "login", user);