Skip to content

Commit

Permalink
feat(minor-ampd): add ability to set log level filters with RUST_LOG …
Browse files Browse the repository at this point in the history
…env var (#612)
  • Loading branch information
cgorenflo authored Sep 19, 2024
1 parent 84f27eb commit a639197
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 9 deletions.
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 config::ConfigError;
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 @@ async fn main() -> ExitCode {
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();
}
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();
}
};
}
Expand Down

0 comments on commit a639197

Please sign in to comment.