Crates/Log
7 articles
How to Add Logging to a Rust Application
Add the `tracing` crate to your project and initialize a subscriber in `main` to capture logs.
How to Filter Logs by Level and Module in Rust
You can filter logs by level and module in Rust by configuring the `tracing` or `env_logger` crate with a specific filter string passed via the `RUST_LOG` environment variable or programmatically.
How to Output Logs as JSON in Rust
Output Rust logs as JSON using the tracing crate with the tracing-subscriber JSON layer for structured logging.
How to Use defmt for Efficient Logging on Embedded Devices
Use the `defmt` crate to replace standard logging with a binary, zero-cost logging system that reduces flash usage and improves performance on embedded devices. Add the `defmt` and `defmt-rtt` dependencies to your `Cargo.toml`, initialize the logger in your entry point, and use `defmt::info!` macros
How to use log crate in Rust logging facade
Add log and env_logger to Cargo.toml, initialize the backend in main, and use log macros to output messages.
How to Use the log Crate in Rust
Add the `log` crate to your dependencies and initialize a logger in your `main` function before using any logging macros.
What Is the Difference Between log and tracing in Rust?
Logging records discrete events, while tracing tracks execution flow and context across asynchronous tasks and function boundaries.