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

Rename light-client to web-client and improve logging for wasm #1277

Merged
merged 2 commits into from
Jan 23, 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
44 changes: 31 additions & 13 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ members = [
"keys",
"lib",
"light-blockchain",
"light-client",
"log",
"macros",
"mempool",
Expand Down Expand Up @@ -58,6 +57,7 @@ members = [
"validator-network",
"vrf",
"wallet",
"web-client",
"zkp-component",
]

Expand Down
11 changes: 7 additions & 4 deletions lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ strum_macros = "0.24"
toml = "0.5"
url = { version = "2.3", features = ["serde"] }
thiserror = "1.0"
tokio = { version = "1.24", features = ["rt", "tracing"], optional = true }
time = { version = "0.3", optional = true }
tokio = { version = "1.24", features = ["rt"], optional = true }
tracing-loki = { version = "0.2.1", optional = true }
tracing-subscriber = { version = "0.3", optional = true }
tracing-web = { version = "0.1", optional = true}

beserial = { path = "../beserial" }
nimiq-block = { path = "../primitives/block" }
Expand All @@ -52,8 +54,8 @@ nimiq-bls = { path = "../bls" }
nimiq-consensus = { path = "../consensus", default-features = false }
nimiq-database = { path = "../database", optional = true }
nimiq-genesis = { path = "../genesis", default-features = false }
nimiq-jsonrpc-core = { git = "https://github.com/nimiq/jsonrpc.git", optional=true}
nimiq-jsonrpc-server = { git = "https://github.com/nimiq/jsonrpc.git", optional=true}
nimiq-jsonrpc-core = { git = "https://github.com/nimiq/jsonrpc.git", optional = true }
nimiq-jsonrpc-server = { git = "https://github.com/nimiq/jsonrpc.git", optional = true }
nimiq-keys = { path = "../keys" }
nimiq-light-blockchain = { path = "../light-blockchain" }
nimiq-log = { path = "../log", optional = true }
Expand Down Expand Up @@ -84,9 +86,10 @@ loki = ["logging", "tracing-loki"]
metrics-server = ["nimiq-metrics-server", "nimiq-network-libp2p/metrics", "nimiq-validator/metrics"]
panic = ["log-panics"]
rpc-server = ["nimiq-jsonrpc-core", "nimiq-jsonrpc-server", "nimiq-rpc-server", "nimiq-wallet", "validator"]
tokio-console = ["console-subscriber", "logging", "tokio"]
tokio-console = ["console-subscriber", "logging", "tokio/tracing"]
validator = ["nimiq-database", "nimiq-mempool", "nimiq-validator", "nimiq-validator-network", "nimiq-rpc-server"]
wallet = ["nimiq-database", "nimiq-wallet"]
websocket = ["nimiq-network-libp2p/websocket"]
web-logging = ["nimiq-log", "time/wasm-bindgen", "tracing-subscriber", "tracing-web"]
zkp-storage = ["nimiq-database", "nimiq-zkp-component/zkp-storage"]
zkp-prover = ["nimiq-zkp-component/zkp-prover"]
10 changes: 4 additions & 6 deletions lib/src/extras/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ use std::sync::Arc;
use file_rotate::{compression::Compression, suffix::AppendCount, ContentLimit, FileRotate};
use log::{level_filters::LevelFilter, Level, Subscriber};
use parking_lot::Mutex;
use tracing_subscriber::filter::Targets;
use tracing_subscriber::fmt::time::SystemTime;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::registry::LookupSpan;
use tracing_subscriber::util::SubscriberInitExt;
use tracing_subscriber::Layer;
use tracing_subscriber::{
filter::Targets, fmt::time::SystemTime, layer::SubscriberExt, registry::LookupSpan,
util::SubscriberInitExt, Layer,
};

use crate::{
config::{command_line::CommandLine, config_file::LogSettings},
Expand Down
7 changes: 4 additions & 3 deletions lib/src/extras/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#[cfg(feature = "deadlock")]
pub mod deadlock;
#[cfg(feature = "launcher")]
pub mod launcher;
#[cfg(feature = "logging")]
pub mod logging;
#[cfg(feature = "metrics-server")]
Expand All @@ -10,6 +12,5 @@ pub mod panic;
pub mod rpc_server;
#[cfg(feature = "signal-handling")]
pub mod signal_handling;

#[cfg(feature = "launcher")]
pub mod launcher;
#[cfg(feature = "web-logging")]
pub mod web_logging;
64 changes: 64 additions & 0 deletions lib/src/extras/web_logging.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
use log::{level_filters::LevelFilter, Level};
use tracing_subscriber::{
filter::Targets, fmt::format::Pretty, layer::SubscriberExt, util::SubscriberInitExt, Layer,
};
use tracing_web::{performance_layer, MakeConsoleWriter};

use crate::{config::config_file::LogSettings, error::Error};
use nimiq_log::{Formatting, MaybeSystemTime, TargetsExt};

pub const DEFAULT_LEVEL: LevelFilter = LevelFilter::INFO;

macro_rules! force_log {
($lvl:expr, $($arg:tt)+) => ({
if log::enabled!($lvl) {
log::event!($lvl, $($arg)+);
}
})
}

pub fn log_error_cause_chain<E: std::error::Error>(e: &E) {
force_log!(Level::ERROR, "{}", e);

if let Some(mut e) = e.source() {
force_log!(Level::ERROR, " caused by");
force_log!(Level::ERROR, " {}", e);

while let Some(source) = e.source() {
force_log!(Level::ERROR, " {}", source);

e = source;
}
}
}

pub fn initialize_web_logging(settings_opt: Option<&LogSettings>) -> Result<(), Error> {
// Get config from config file
let settings = settings_opt.cloned().unwrap_or_default();

// Set logging level for Nimiq and all other modules
// Creating ZKPs with a log level below WARN will consume huge amounts of memory due to tracing annotations in the dependency.
// That's why we specifically set its log level to WARN.
let mut filter = Targets::new()
.with_default(DEFAULT_LEVEL)
.with_nimiq_targets(settings.level.unwrap_or(DEFAULT_LEVEL))
.with_target("r1cs", LevelFilter::WARN);
// Set logging level for specific selected modules
filter = filter.with_targets(settings.tags);
// Set logging level from the environment
filter = filter.with_env();

let perf_layer = performance_layer().with_details_from_fields(Pretty::default());

tracing_subscriber::registry()
.with(
tracing_subscriber::fmt::layer()
.with_writer(MakeConsoleWriter)
.with_ansi(settings.file.is_none())
.event_format(Formatting(MaybeSystemTime(settings.timestamps)))
.with_filter(filter),
)
.with(perf_layer)
.init();
Ok(())
}
14 changes: 0 additions & 14 deletions light-client/nimiq-client.service

This file was deleted.

Loading