Skip to content

Commit

Permalink
Draft remove all init_logger part to use a common way for all crates.
Browse files Browse the repository at this point in the history
  • Loading branch information
Douceur committed Nov 20, 2024
1 parent 95bfe78 commit 11c3268
Show file tree
Hide file tree
Showing 24 changed files with 122 additions and 98 deletions.
32 changes: 32 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ subspace-core-primitives = { opt-level = 3 }
subspace-erasure-coding = { opt-level = 3 }
subspace-farmer-components = { opt-level = 3 }
subspace-kzg = { opt-level = 3 }
subspace-logging = { opt-level = 3 }
subspace-proof-of-space = { opt-level = 3 }
subspace-proof-of-time = { opt-level = 3 }
substrate-bip39 = { opt-level = 3 }
Expand Down
1 change: 1 addition & 0 deletions crates/pallet-subspace/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ subspace-core-primitives = { version = "0.1.0", path = "../subspace-core-primiti
subspace-erasure-coding = { version = "0.1.0", path = "../subspace-erasure-coding" }
subspace-farmer-components = { version = "0.1.0", path = "../subspace-farmer-components" }
subspace-kzg = { version = "0.1.0", path = "../../shared/subspace-kzg" }
subspace-logging = { version = "0.0.1", path = "../../shared/subspace-logging" }
subspace-proof-of-space = { version = "0.1.0", path = "../subspace-proof-of-space" }

[features]
Expand Down
1 change: 1 addition & 0 deletions crates/sc-consensus-subspace-rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ subspace-core-primitives = { version = "0.1.0", path = "../subspace-core-primiti
subspace-erasure-coding = { version = "0.1.0", path = "../subspace-erasure-coding" }
subspace-farmer-components = { version = "0.1.0", path = "../subspace-farmer-components" }
subspace-kzg = { version = "0.1.0", path = "../../shared/subspace-kzg" }
subspace-logging = { version = "0.0.1", path = "../../shared/subspace-logging" }
subspace-networking = { version = "0.1.0", path = "../subspace-networking" }
subspace-rpc-primitives = { version = "0.1.0", path = "../subspace-rpc-primitives" }
thiserror = "2.0.0"
Expand Down
1 change: 1 addition & 0 deletions crates/sc-consensus-subspace/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ subspace-archiving = { version = "0.1.0", path = "../subspace-archiving" }
subspace-core-primitives = { version = "0.1.0", path = "../subspace-core-primitives" }
subspace-erasure-coding = { version = "0.1.0", path = "../subspace-erasure-coding" }
subspace-kzg = { version = "0.1.0", path = "../../shared/subspace-kzg" }
subspace-logging = { version = "0.0.1", path = "../../shared/subspace-logging" }
subspace-proof-of-space = { version = "0.1.0", path = "../subspace-proof-of-space" }
subspace-verification = { version = "0.1.0", path = "../subspace-verification" }
thiserror = "2.0.0"
Expand Down
1 change: 1 addition & 0 deletions crates/subspace-farmer-components/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ subspace-archiving = { version = "0.1.0", path = "../subspace-archiving" }
subspace-core-primitives = { version = "0.1.0", path = "../subspace-core-primitives" }
subspace-erasure-coding = { version = "0.1.0", path = "../subspace-erasure-coding" }
subspace-kzg = { version = "0.1.0", path = "../../shared/subspace-kzg" }
subspace-logging = { version = "0.0.1", path = "../../shared/subspace-logging" }
subspace-proof-of-space = { version = "0.1.0", path = "../subspace-proof-of-space", features = ["parallel"] }
subspace-verification = { version = "0.1.0", path = "../subspace-verification" }
thiserror = "2.0.0"
Expand Down
1 change: 1 addition & 0 deletions crates/subspace-farmer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ subspace-erasure-coding = { version = "0.1.0", path = "../subspace-erasure-codin
subspace-farmer-components = { version = "0.1.0", path = "../subspace-farmer-components" }
subspace-core-primitives = { version = "0.1.0", path = "../subspace-core-primitives" }
subspace-kzg = { version = "0.1.0", path = "../../shared/subspace-kzg" }
subspace-logging = { version = "0.0.1", path = "../../shared/subspace-logging" }
subspace-metrics = { version = "0.1.0", path = "../../shared/subspace-metrics", optional = true }
subspace-networking = { version = "0.1.0", path = "../subspace-networking" }
subspace-proof-of-space = { version = "0.1.0", path = "../subspace-proof-of-space" }
Expand Down
1 change: 1 addition & 0 deletions crates/subspace-gateway/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ subspace-data-retrieval = { version = "0.1.0", path = "../../shared/subspace-dat
subspace-erasure-coding = { version = "0.1.0", path = "../subspace-erasure-coding" }
subspace-gateway-rpc = { version = "0.1.0", path = "../subspace-gateway-rpc" }
subspace-kzg = { version = "0.1.0", path = "../../shared/subspace-kzg" }
subspace-logging = { version = "0.0.1", path = "../../shared/subspace-logging" }
subspace-networking = { version = "0.1.0", path = "../subspace-networking" }
subspace-rpc-primitives = { version = "0.1.0", path = "../subspace-rpc-primitives" }
subspace-verification = { version = "0.1.0", path = "../subspace-verification", default-features = false }
Expand Down
21 changes: 1 addition & 20 deletions crates/subspace-gateway/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::panic;
use std::process::exit;
use tokio::signal;
use tracing::level_filters::LevelFilter;
use tracing::{debug, warn};
use tracing::{debug, info, warn};
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
use tracing_subscriber::{fmt, EnvFilter, Layer};
Expand All @@ -32,25 +32,6 @@ pub(crate) fn set_exit_on_panic() {
}));
}

pub(crate) fn init_logger() {
// TODO: Workaround for https://github.com/tokio-rs/tracing/issues/2214, also on
// Windows terminal doesn't support the same colors as bash does
let enable_color = if cfg!(windows) {
false
} else {
supports_color::on(supports_color::Stream::Stderr).is_some()
};
tracing_subscriber::registry()
.with(
fmt::layer().with_ansi(enable_color).with_filter(
EnvFilter::builder()
.with_default_directive(LevelFilter::INFO.into())
.from_env_lossy(),
),
)
.init();
}

pub(crate) fn raise_fd_limit() {
match fdlimit::raise_fd_limit() {
Ok(fdlimit::Outcome::LimitRaised { from, to }) => {
Expand Down
5 changes: 3 additions & 2 deletions crates/subspace-gateway/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ mod node_client;
mod piece_getter;
mod piece_validator;

use crate::commands::{init_logger, raise_fd_limit, set_exit_on_panic, Command};
use crate::commands::{raise_fd_limit, set_exit_on_panic, Command};
use clap::Parser;
use subspace_logging::init_logger;

#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
set_exit_on_panic();
init_logger();
init_logger(false);
raise_fd_limit();

let command = Command::parse();
Expand Down
2 changes: 2 additions & 0 deletions crates/subspace-networking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
unsigned-varint = { version = "0.8.0", features = ["futures", "asynchronous_codec"] }
void = "1.0.2"
subspace-logging = { version = "0.0.1", path = "../../shared/subspace-logging" }


[dependencies.libp2p]
# TODO: Replace with upstream once https://github.com/libp2p/rust-libp2p/issues/5626 and
Expand Down
14 changes: 1 addition & 13 deletions crates/subspace-networking/examples/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ enum Command {

#[tokio::main]
async fn main() {
init_logging();

init_logger(false);
let args: Args = Args::parse();

info!(?args, "Benchmark started.");
Expand Down Expand Up @@ -395,14 +394,3 @@ pub async fn configure_dsn(

node
}

fn init_logging() {
// set default log to info if the RUST_LOG is not set.
let env_filter = EnvFilter::builder()
.with_default_directive(Level::INFO.into())
.from_env_lossy();

let builder = Subscriber::builder().with_env_filter(env_filter).finish();

builder.init()
}
14 changes: 2 additions & 12 deletions crates/subspace-networking/examples/random-walker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::collections::HashMap;
use std::sync::Arc;
use std::time::{Duration, Instant};
use subspace_core_primitives::pieces::PieceIndex;
use subspace_logging::init_logger;
use subspace_networking::protocols::request_response::handlers::piece_by_index::{
PieceByIndexRequest, PieceByIndexRequestHandler, PieceByIndexResponse,
};
Expand Down Expand Up @@ -47,7 +48,7 @@ struct Args {

#[tokio::main]
async fn main() {
init_logging();
init_logger(false);

let args: Args = Args::parse();

Expand Down Expand Up @@ -416,14 +417,3 @@ async fn configure_dsn(

node
}

fn init_logging() {
// set default log to info if the RUST_LOG is not set.
let env_filter = EnvFilter::builder()
.with_default_directive(Level::INFO.into())
.from_env_lossy();

let builder = Subscriber::builder().with_env_filter(env_filter).finish();

builder.init()
}
15 changes: 2 additions & 13 deletions crates/subspace-networking/src/bin/subspace-bootstrap-node/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr};
use std::panic;
use std::process::exit;
use std::sync::Arc;
use subspace_logging::init_logger;
use subspace_metrics::{start_prometheus_metrics_server, RegistryAdapter};
use subspace_networking::libp2p::multiaddr::Protocol;
use subspace_networking::{peer_id, Config, KademliaMode};
Expand Down Expand Up @@ -117,22 +118,10 @@ fn set_exit_on_panic() {
}));
}

fn init_logging() {
// set default log to info if the RUST_LOG is not set.
let env_filter = EnvFilter::builder()
.with_default_directive(Level::INFO.into())
.from_env_lossy();

let builder = Subscriber::builder().with_env_filter(env_filter).finish();

builder.init()
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
set_exit_on_panic();
init_logging();

init_logger(false);
let command: Command = Command::parse();

match command {
Expand Down
3 changes: 2 additions & 1 deletion crates/subspace-node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ thiserror = "2.0.0"
tokio = { version = "1.40.0", features = ["macros"] }
tokio-stream = "0.1.16"
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
tracing-subscriber = { version = "0.3.18", features = ["env-filter", "json"] }
subspace-logging = { version = "0.0.1", path = "../../shared/subspace-logging" }

[build-dependencies]
substrate-build-script-utils = { git = "https://github.com/subspace/polkadot-sdk", rev = "94a1a8143a89bbe9f938c1939ff68abc1519a305" }
Expand Down
10 changes: 3 additions & 7 deletions crates/subspace-node/src/commands/domain_key.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use crate::commands::shared::{
derive_keypair, init_logger, store_key_in_keystore, KeystoreOptions,
};
use crate::commands::shared::{derive_keypair, store_key_in_keystore, KeystoreOptions};
use bip39::Mnemonic;
use clap::Parser;
use sc_cli::{Error, KeystoreParams};
Expand All @@ -9,6 +7,7 @@ use sp_core::crypto::{ExposeSecret, SecretString};
use sp_core::Pair;
use sp_domains::DomainId;
use std::path::PathBuf;
use subspace_logging::init_logger;
use tracing::{info, warn};

/// Options for creating domain key
Expand All @@ -26,8 +25,7 @@ pub struct CreateDomainKeyOptions {
}

pub fn create_domain_key(options: CreateDomainKeyOptions) -> Result<(), Error> {
init_logger();

init_logger(false);
let CreateDomainKeyOptions {
base_path,
domain_id,
Expand Down Expand Up @@ -94,8 +92,6 @@ pub struct InsertDomainKeyOptions {
}

pub fn insert_domain_key(options: InsertDomainKeyOptions) -> Result<(), Error> {
init_logger();

let InsertDomainKeyOptions {
base_path,
domain_id,
Expand Down
Loading

0 comments on commit 11c3268

Please sign in to comment.