workspace-filter 0.1.0

Simple framework to compile env filters for all packages in a workspace
Documentation
  • Coverage
  • 100%
    2 out of 2 items documented0 out of 1 items with examples
  • Size
  • Source code size: 5.08 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 242.67 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 12s Average build duration of successful builds.
  • all releases: 12s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • ozwaldorf/workspace-filter
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • ozwaldorf

Workspace Filter

Simple framework to compile env filters for all packages in a workspace.

Setup

First, add the two dependencies to your crate:

[dependencies]
workspace-filter = "0.1"

[build-dependencies]
workspace-filter-build = "0.1"

Then, call the build function in your build.rs file:

fn main() -> Result<(), Box<dyn std::error::Error> {
    // NOTE: This will rerun the entire build script if Cargo.lock changes
    workspace_filter_build::build()?;
}

The macro can then be used in your crate, with a few example use-cases shown below:

Simple Usage

If you only care to set the filter for your workspace dependencies:

let filter = workspace_filter!("debug");
let env_filter = EnvFilter::builder().parse_lossy(filter);

Manual filters can be included, for example to make workspace crates at debug and everything else at info:

let filter = workspace_filter!("debug", "info");
let env_filter = EnvFilter::builder().parse_lossy(filter);

In the catchall argument, {level} can be also used anywhere to substitute the given workspace level.

let filter = workspace_filter!("debug", "trace,my-bin={level}");
let env_filter = EnvFilter::builder().parse_lossy(filter);

Verbosity level Example

Example that overrides with RUST_LOG, or falls back to increasing the verbosity for the workspace and other deps depending on a given number

let filter = std::env::var("RUST_LOG").unwrap_or_else(|_| {
    // Fallback which is directed by the verbosity flag
    match args.verbose {
        0 => "info".into(),
        1 => workspace_filter!("debug", "info"),
        2 => workspace_filter!("trace", "info"),
        3 => workspace_filter!("trace", "debug"),
        _ => "trace".into(),
    }
});
let env_filter = EnvFilter::builder().parse_lossy(filter);