From 63ea9566249dc106f8c6656ba1021f190a98b902 Mon Sep 17 00:00:00 2001 From: slinkydeveloper Date: Mon, 24 Apr 2023 09:58:11 +0200 Subject: [PATCH] Enable info log by default --- README.md | 2 +- src/tracing_instrumentation/src/lib.rs | 23 +++++++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index df69fe3cb..bf5151d88 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Restate supports the following SDKs: You can start the runtime via: ```shell -RUST_LOG=info just run --release +just run --release ``` In order to change the log level, configure the [`RUST_LOG` env variable](https://rust-lang-nursery.github.io/rust-cookbook/development_tools/debugging/config_log.html#enable-log-levels-per-module) respectively. diff --git a/src/tracing_instrumentation/src/lib.rs b/src/tracing_instrumentation/src/lib.rs index 0f4cb5a03..3e658b44a 100644 --- a/src/tracing_instrumentation/src/lib.rs +++ b/src/tracing_instrumentation/src/lib.rs @@ -5,6 +5,7 @@ use opentelemetry::trace::TraceError; use pretty::Pretty; use std::fmt::Display; use tracing::Level; +use tracing_subscriber::filter::ParseError; use tracing_subscriber::fmt::time::SystemTime; use tracing_subscriber::fmt::writer::MakeWriterExt; use tracing_subscriber::layer::SubscriberExt; @@ -13,9 +14,14 @@ use tracing_subscriber::{EnvFilter, Layer}; #[derive(Debug, thiserror::Error)] #[error("could not initialize tracing {trace_error}")] -pub struct Error { - #[from] - trace_error: TraceError, +pub enum Error { + #[error("could not initialize tracing: {0}")] + Tracing(#[from] TraceError), + #[error( + "cannot parse log configuration {} environment variable: {0}", + EnvFilter::DEFAULT_ENV + )] + LogDirectiveParseError(#[from] ParseError), } pub type TracingResult = Result; @@ -93,8 +99,17 @@ impl Options { .boxed(), }; + // Check if we have env variable + let env_filter = if let Ok(var) = std::env::var(EnvFilter::DEFAULT_ENV) { + EnvFilter::builder().parse(var)? + } else { + EnvFilter::new("warn,restate=info") + }; + + println!("LOG: {}", env_filter); + let layers = tracing_subscriber::registry() - .with(EnvFilter::from_default_env()) + .with(env_filter) .with(fmt_layer); #[cfg(feature = "console-subscriber")] let layers = layers.with(console_subscriber::spawn());