1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-07-29 22:01:14 +03:00

Minor logging improvements

- only have colors if the output terminal is a tty
 - log in a non-blocking fashion
This commit is contained in:
Quentin Gliech
2022-01-26 17:21:54 +01:00
parent c3ac36190d
commit c7a243a3a1
3 changed files with 19 additions and 1 deletions

13
Cargo.lock generated
View File

@ -1847,6 +1847,7 @@ version = "0.1.0"
dependencies = [
"anyhow",
"argon2",
"atty",
"clap",
"dotenv",
"futures 0.3.19",
@ -1872,6 +1873,7 @@ dependencies = [
"tower",
"tower-http",
"tracing",
"tracing-appender",
"tracing-opentelemetry",
"tracing-subscriber",
"url",
@ -4118,6 +4120,17 @@ dependencies = [
"tracing-core",
]
[[package]]
name = "tracing-appender"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94571df2eae3ed4353815ea5a90974a594a1792d8782ff2cbcc9392d1101f366"
dependencies = [
"crossbeam-channel 0.5.2",
"time 0.3.6",
"tracing-subscriber",
]
[[package]]
name = "tracing-attributes"
version = "0.1.18"

View File

@ -21,8 +21,10 @@ url = "2.2.2"
argon2 = { version = "0.3.2", features = ["password-hash"] }
reqwest = { version = "0.11.9", features = ["rustls-tls"], default-features = false, optional = true }
watchman_client = "0.7.1"
atty = "0.2.14"
tracing = "0.1.29"
tracing-appender = "0.2.0"
tracing-subscriber = { version = "0.3.6", features = ["env-filter"] }
tracing-opentelemetry = "0.16.0"
opentelemetry = { version = "0.16.0", features = ["trace", "metrics", "rt-tokio"] }

View File

@ -112,7 +112,10 @@ async fn try_main() -> anyhow::Result<()> {
// Setup logging
// This writes logs to stderr
let fmt_layer = tracing_subscriber::fmt::layer().with_writer(std::io::stderr);
let (log_writer, _guard) = tracing_appender::non_blocking(std::io::stderr());
let fmt_layer = tracing_subscriber::fmt::layer()
.with_writer(log_writer)
.with_ansi(atty::is(atty::Stream::Stderr));
let filter_layer = EnvFilter::try_from_default_env()
.or_else(|_| EnvFilter::try_new("info"))
.context("could not setup logging filter")?;