Skip to content

Commit

Permalink
added the ability to controll the loglevel at runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
CommanderStorm committed Jun 18, 2024
1 parent fd01872 commit 5df093e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
1 change: 1 addition & 0 deletions server/main-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ The server should now be available on `localhost:8080` if you have configured th
|-----------------------------------|----------------------------------|-----------------------------------------|--------------------------------------------------------------------------------------------------------|
| `POSTGRES_{USER,PASSWORD,URL,DB}` | [`all`](./main.rs) | required | Used to connect to the db |
| `GIT_COMMIT_SHA` | [`main`](./main.rs) | optional | Shown in the status endpint (also set at build time in docker) |
| `LOG_LEVEL` | [`main`](./main.rs) | optional | Shown in the status endpint (also set at build time in docker) |
| `GITHUB_TOKEN` | [`feedback`](./feeedback/mod.rs) | | A GitHub token with `write` access to `repo`.<br/>This is used to create issues/PRs on the repository. |
| `JWT_KEY` | [`feedback`](./feeedback/mod.rs) | | A key used to sign JWTs.<br/>This is used to authenticate that feedback tokens were given out by us. |
| `MIELI_{URL,MASTER_KEY}` | [`search`](./search/mod.rs) | | Allows searching via meiliserch |
Expand Down
19 changes: 12 additions & 7 deletions server/main-api/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,22 @@ fn connection_string() -> String {
fn setup_logging() {
#[cfg(debug_assertions)]
{
let log_level = std::env::var("LOG_LEVEL").unwrap_or_else(|_|"debug".to_string());
let filter = format!("{log_level},hyper=info,rustls=info,h2=info,sqlx=info,hickory_resolver=info,hickory_proto=info");
let env = env_logger::Env::default()
.default_filter_or("debug,hyper=info,rustls=info,h2=info,sqlx=info,hickory_resolver=info,hickory_proto=info");
.default_filter_or(&filter);
env_logger::Builder::from_env(env).init();
}
#[cfg(not(debug_assertions))]
structured_logger::Builder::with_level("info")
.with_target_writer(
"*",
structured_logger::async_json::new_writer(tokio::io::stdout()),
)
.init();
{
let log_level = std::env::var("LOG_LEVEL").unwrap_or_else(|_|"info".to_string());
structured_logger::Builder::with_level(&log_level)
.with_target_writer(
"*",
structured_logger::async_json::new_writer(tokio::io::stdout()),
)
.init();
}
}

#[tokio::main]
Expand Down

0 comments on commit 5df093e

Please sign in to comment.