Problem
When the global log level is set to trace or debug, noisy third-party crates (e.g., tokenizers::tokenizer::normalizer) produce millions of log lines that drown out the application's own trace/debug output. Currently, twyg only supports a single global log level with no way to suppress specific modules.
Desired Behavior
Add a module_filters option that maps module path prefixes to log levels, similar to RUST_LOG=info,tokenizers=warn. This allows users to set a verbose global level while suppressing noisy crates:
let opts = OptsBuilder::new()
.level(LogLevel::Trace)
.module_filter("tokenizers", LogLevel::Warn)
.module_filter("hyper", LogLevel::Info)
.build()
.unwrap();
Proposed API
Opts field: module_filters: Vec<(String, LogLevel)> — ordered list of (prefix, level) pairs
OptsBuilder methods:
module_filter(prefix, level) — add a single filter
module_filters(filters) — set all filters at once
Opts accessor: module_filters() -> &[(String, LogLevel)]
- Serde support: serializable/deserializable with
#[serde(default)]
Behavior
- On each log event,
enabled() checks the record's target against prefixes in order
- First matching prefix determines the effective level for that module
- Unmatched modules use the global
level
log::set_max_level() is set to the most permissive of global + all filter levels so messages reach the custom enabled() check
Problem
When the global log level is set to
traceordebug, noisy third-party crates (e.g.,tokenizers::tokenizer::normalizer) produce millions of log lines that drown out the application's own trace/debug output. Currently, twyg only supports a single global log level with no way to suppress specific modules.Desired Behavior
Add a
module_filtersoption that maps module path prefixes to log levels, similar toRUST_LOG=info,tokenizers=warn. This allows users to set a verbose global level while suppressing noisy crates:Proposed API
Optsfield:module_filters: Vec<(String, LogLevel)>— ordered list of (prefix, level) pairsOptsBuildermethods:module_filter(prefix, level)— add a single filtermodule_filters(filters)— set all filters at onceOptsaccessor:module_filters() -> &[(String, LogLevel)]#[serde(default)]Behavior
enabled()checks the record's target against prefixes in orderlevellog::set_max_level()is set to the most permissive of global + all filter levels so messages reach the customenabled()check