Skip to content

Commit 20b959d

Browse files
authored
fix: use INFO as default level for logs (#353)
* fix: set default rust log to info tap-agent * style: cargo fmt applied * feat: Add tracing subscriber to indexer-service * feat: move init_tracing to a function outside main
1 parent 7d515df commit 20b959d

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

service/src/main.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,32 @@
44
use std::process::ExitCode;
55

66
use indexer_service_rs::service::run;
7+
use tracing::level_filters::LevelFilter;
8+
use tracing::subscriber::set_global_default;
9+
use tracing_subscriber::{EnvFilter, FmtSubscriber};
710

811
#[tokio::main]
912
async fn main() -> ExitCode {
10-
tracing_subscriber::fmt::init();
13+
init_tracing();
1114
if let Err(e) = run().await {
1215
tracing::error!("Indexer service error: {e}");
1316
return ExitCode::from(1);
1417
}
1518
ExitCode::SUCCESS
1619
}
20+
21+
fn init_tracing() {
22+
// Tracing setup
23+
let filter = EnvFilter::builder()
24+
.with_default_directive(LevelFilter::INFO.into())
25+
.from_env_lossy();
26+
let subscriber_builder: tracing_subscriber::fmt::SubscriberBuilder<
27+
tracing_subscriber::fmt::format::DefaultFields,
28+
tracing_subscriber::fmt::format::Format,
29+
EnvFilter,
30+
> = FmtSubscriber::builder().with_env_filter(filter);
31+
set_global_default(subscriber_builder.with_ansi(true).pretty().finish()).expect(
32+
"Could not set up global default subscriber for logger, check \
33+
environmental variable `RUST_LOG`",
34+
);
35+
}

tap-agent/src/config.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
// Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs.
22
// SPDX-License-Identifier: Apache-2.0
33

4+
use anyhow::Result;
45
use clap::Parser;
56
use indexer_config::{Config as IndexerConfig, ConfigPrefix};
67
use reqwest::Url;
78
use std::path::PathBuf;
89
use std::{collections::HashMap, str::FromStr};
9-
use tracing::error;
10-
11-
use anyhow::Result;
1210
use thegraph_core::{Address, DeploymentId};
1311
use tracing::subscriber::{set_global_default, SetGlobalDefaultError};
12+
use tracing::{error, level_filters::LevelFilter};
1413
use tracing_subscriber::{EnvFilter, FmtSubscriber};
1514

1615
#[derive(Parser)]
@@ -165,7 +164,9 @@ pub struct Tap {
165164

166165
/// Sets up tracing, allows log level to be set from the environment variables
167166
fn init_tracing(format: String) -> Result<(), SetGlobalDefaultError> {
168-
let filter = EnvFilter::from_default_env();
167+
let filter = EnvFilter::builder()
168+
.with_default_directive(LevelFilter::INFO.into())
169+
.from_env_lossy();
169170
let subscriber_builder: tracing_subscriber::fmt::SubscriberBuilder<
170171
tracing_subscriber::fmt::format::DefaultFields,
171172
tracing_subscriber::fmt::format::Format,

0 commit comments

Comments
 (0)