Skip to content

Commit

Permalink
Uniformly set default log level to INFO
Browse files Browse the repository at this point in the history
Commit a98f548 ("Capture INFO and WARN from tracing by default")
adjusted the tracing part of the crate to use the INFO log level by
default. With this change we switch the log part over to doing the same.
  • Loading branch information
d-e-s-o committed Jan 12, 2025
1 parent c91596c commit ed14486
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Unreleased
----------
- Changed default log level to `INFO`


0.2.16
------
- Use `tracing-subscriber`'s `tracing-log` feature to unify log output
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,11 @@ $ cargo test -- --nocapture
```

Furthermore, the `RUST_LOG` environment variable is honored and can be
used to influence the log level to work with (among other things).
Please refer to the [`env_logger` docs][env-docs-rs] and
used to influence the log level to work with (among other things). By
default, log messages of criticality `INFO` (and higher) will be
emitted. Please refer to the [`env_logger` docs][env-docs-rs] and
[`tracing-subscriber`][tracing-env-docs-rs] documentation for supported
syntax and more information.
variable syntax and more information.

If the `trace` feature is enabled, the `RUST_LOG_SPAN_EVENTS`
environment variable can be used to configure the tracing subscriber to
Expand Down
23 changes: 11 additions & 12 deletions macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,21 +155,20 @@ impl AttributeArgs {
/// Expand the initialization code for the `log` crate.
#[cfg(all(feature = "log", not(feature = "trace")))]
fn expand_logging_init(attribute_args: &AttributeArgs) -> Tokens {
let add_default_log_filter = if let Some(default_log_filter) = &attribute_args.default_log_filter
{
quote! {
let env_logger_builder = env_logger_builder
.parse_env(::test_log::env_logger::Env::default().default_filter_or(#default_log_filter));
}
} else {
quote! {}
};
let default_filter = attribute_args
.default_log_filter
.as_ref()
.unwrap_or(&::std::borrow::Cow::Borrowed("info"));

quote! {
{
let mut env_logger_builder = ::test_log::env_logger::builder();
#add_default_log_filter
let _ = env_logger_builder.is_test(true).try_init();
let _result = ::test_log::env_logger::builder()
.parse_env(
::test_log::env_logger::Env::default()
.default_filter_or(#default_filter)
)
.is_test(true)
.try_init();
}
}
}
Expand Down

0 comments on commit ed14486

Please sign in to comment.