Add better default logging configurations for development

This commit is contained in:
Zhaofeng Li 2023-05-08 12:59:57 -06:00
parent b1b798ef40
commit a6692a364e
3 changed files with 51 additions and 2 deletions

37
Cargo.lock generated
View file

@ -638,6 +638,15 @@ dependencies = [
"cfg-if",
]
[[package]]
name = "matchers"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558"
dependencies = [
"regex-automata",
]
[[package]]
name = "matchit"
version = "0.7.0"
@ -816,6 +825,30 @@ dependencies = [
"getrandom",
]
[[package]]
name = "regex"
version = "1.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b1f693b24f6ac912f4893ef08244d70b6067480d2f1a46e950c9691e6749d1d"
dependencies = [
"regex-syntax",
]
[[package]]
name = "regex-automata"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
dependencies = [
"regex-syntax",
]
[[package]]
name = "regex-syntax"
version = "0.6.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1"
[[package]]
name = "reqwest"
version = "0.11.17"
@ -1327,10 +1360,14 @@ version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30a651bc37f915e81f087d86e62a18eec5f79550c7faff886f7090b4ea757c77"
dependencies = [
"matchers",
"nu-ansi-term",
"once_cell",
"regex",
"sharded-slab",
"smallvec",
"thread_local",
"tracing",
"tracing-core",
"tracing-log",
]

View file

@ -11,7 +11,7 @@ gha-cache = { path = "../gha-cache" }
axum = "0.6.18"
clap = { version = "4.2.7", features = ["derive"] }
tracing = "0.1.37"
tracing-subscriber = "0.3.17"
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
tower-http = { version = "0.4.0", features = ["trace"] }
serde_json = "1.0.96"
thiserror = "1.0.40"

View file

@ -30,6 +30,7 @@ use clap::Parser;
use tokio::fs;
use tokio_stream::StreamExt;
use tokio_util::io::StreamReader;
use tracing_subscriber::EnvFilter;
use error::{Error, Result};
use gha_cache::{Api, Credentials};
@ -78,7 +79,7 @@ struct StateInner {
async fn main() {
let args = Args::parse();
tracing_subscriber::fmt::init();
init_logging();
let credentials = if let Some(credentials_file) = &args.credentials_file {
tracing::info!("Loading credentials from {:?}", credentials_file);
@ -128,6 +129,17 @@ async fn main() {
.unwrap();
}
fn init_logging() {
let filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| {
#[cfg(debug_assertions)]
return EnvFilter::new("gha_cache=debug,nix_action_cache=debug");
#[cfg(not(debug_assertions))]
return EnvFilter::default();
});
tracing_subscriber::fmt().with_env_filter(filter).init();
}
#[cfg(debug_assertions)]
async fn dump_api_stats<B>(
Extension(state): Extension<State>,