Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(minor-ampd): add ability to set log level filters with RUST_LOG env var #612

Merged
merged 2 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 34 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ampd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ toml = "0.5.9"
tonic = "0.9.2"
tracing = { version = "0.1.37", features = ["valuable", "log"] }
tracing-core = { version = "0.1.30", features = ["valuable"] }
tracing-subscriber = { version = "0.3.16", features = ["json", "valuable"] }
tracing-subscriber = { version = "0.3.16", features = ["json", "valuable", "env-filter"] }
typed-builder = "0.18.2"
url = "2.3.1"
valuable = { version = "0.1.0", features = ["derive"] }
Expand Down
21 changes: 19 additions & 2 deletions ampd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
use error_stack::{Report, ResultExt};
use report::LoggableError;
use tracing::{error, info};
use tracing_core::LevelFilter;
use tracing_subscriber::EnvFilter;
use valuable::Valuable;

#[derive(Debug, Parser, Valuable)]
Expand Down Expand Up @@ -94,10 +96,25 @@
fn set_up_logger(output: &Output) {
match output {
Output::Json => {
tracing_subscriber::fmt().json().flatten_event(true).init();
tracing_subscriber::fmt()
.json()
.flatten_event(true)
.with_env_filter(
EnvFilter::builder()
.with_default_directive(LevelFilter::INFO.into())
.from_env_lossy(),
)
.init();

Check warning on line 107 in ampd/src/main.rs

View check run for this annotation

Codecov / codecov/patch

ampd/src/main.rs#L99-L107

Added lines #L99 - L107 were not covered by tests
}
Output::Text => {
tracing_subscriber::fmt().compact().init();
tracing_subscriber::fmt()
.compact()
.with_env_filter(
EnvFilter::builder()
.with_default_directive(LevelFilter::INFO.into())
.from_env_lossy(),
)
.init();

Check warning on line 117 in ampd/src/main.rs

View check run for this annotation

Codecov / codecov/patch

ampd/src/main.rs#L110-L117

Added lines #L110 - L117 were not covered by tests
}
};
}
Expand Down
Loading