Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable info log by default #331

Merged
merged 1 commit into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
23 changes: 19 additions & 4 deletions src/tracing_instrumentation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<T> = Result<T, Error>;
Expand Down Expand Up @@ -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());
Expand Down