Skip to content

Add per-module log level filtering#9

Open
oubiwann wants to merge 1 commit into
release/0.6.xfrom
feature/module-log-filters
Open

Add per-module log level filtering#9
oubiwann wants to merge 1 commit into
release/0.6.xfrom
feature/module-log-filters

Conversation

@oubiwann
Copy link
Copy Markdown
Contributor

Summary

  • Add module_filters field to Opts and OptsBuilder for per-module log level overrides
  • Module filters match log record targets by prefix; first matching prefix wins
  • Unmatched modules fall back to the global level
  • log::set_max_level() set to the most permissive level across global + all filters so messages reach the custom enabled() check

Example usage

let opts = OptsBuilder::new()
    .level(LogLevel::Trace)
    .module_filter("tokenizers", LogLevel::Warn)
    .module_filter("hyper", LogLevel::Info)
    .build()
    .unwrap();

This suppresses tokenizers TRACE/DEBUG/INFO while keeping TRACE for everything else.

Files changed

File Changes
src/opts.rs module_filters field on Opts + OptsBuilder, accessor, builder methods, serde support, 5 new tests
src/logger.rs module_filters on LoggerConfig, per-module filtering in enabled(), effective max level in dispatch(), 5 new tests
src/lib.rs Updated setup() doc comment with module_filters example

Test plan

  • All 156 unit tests pass
  • All 15 integration tests pass
  • All 12 doc tests pass (2 new)
  • cargo clippy -- -D warnings clean
  • cargo fmt --check clean
  • Manual verification with a program that sets level=Trace, module_filters=[("tokenizers", Warn)]

Closes #8

🤖 Generated with Claude Code

Allow users to suppress noisy third-party crates while keeping verbose
logging for their own code, similar to RUST_LOG=info,tokenizers=warn.

New Opts field `module_filters: Vec<(String, LogLevel)>` with builder
methods `module_filter()` and `module_filters()`. Filters match log
record targets by prefix; first match wins. The effective max level
passed to log::set_max_level() is the most permissive among global +
all filter levels so messages still reach the custom enabled() check.

Closes #8

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add per-module log level filtering

1 participant