Skip to content

Commit

Permalink
Improve logging: replace log with tracing (#72)
Browse files Browse the repository at this point in the history
* feat(crypto-helper): update rust-toolchain.toml and Cargo.lock;

* feat(crypto-helper): replace log crate with tracing;

* feat(crypto-helper): improve logging;
  • Loading branch information
TheBestTvarynka authored Aug 23, 2024
1 parent 5f32ffc commit 47996f4
Show file tree
Hide file tree
Showing 10 changed files with 486 additions and 289 deletions.
728 changes: 449 additions & 279 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ wasm-bindgen = "0.2"
web-sys = { version = "0.3", features = ["Window"] }

# logging
wasm-logger = "0.2"
log = "0.4"
tracing-web = "0.1"
tracing-subscriber = { version = "0.3", default-features = false, features = ["std", "fmt", "time", "ansi", "env-filter"] }
tracing = "0.1"

# utils
hex = "0.4"
Expand Down
2 changes: 1 addition & 1 deletion crates/asn1-parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ prop-strategies = { path = "../prop-strategies" }
proptest = "1.2.0"

[dependencies]
log = "0.4.20"
tracing = "0.1"
num-bigint-dig = { version = "0.8.4", default-features = false }
num-traits = { version = "0.2.17", default-features = false }
oid = { version = "0.2.1", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion crates/asn1-parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mod macros;

#[allow(unused_imports)]
#[macro_use]
extern crate log;
extern crate tracing;

mod asn1;
mod constructors;
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "1.77.0"
channel = "1.80.1"
components = [ "rustfmt", "clippy" ]
2 changes: 1 addition & 1 deletion src/asn1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ pub fn asn1_parser_page() -> Html {
asn1_setter.set(asn1.to_owned_with_asn1(asn1.inner_asn1().to_owned()));
}
Err(err) => {
error!("Can not decode asn1: {:?}", err);
error!(?err, "Can not decode asn1.");
}
}
raw_asn1_setter.set(bytes);
Expand Down
15 changes: 14 additions & 1 deletion src/bin/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
use crypto_helper::App;
use tracing_subscriber::fmt::format::Pretty;
use tracing_subscriber::prelude::*;
use tracing_subscriber::EnvFilter;
use tracing_web::{performance_layer, MakeWebConsoleWriter};

fn main() {
wasm_logger::init(wasm_logger::Config::default());
let fmt_layer = tracing_subscriber::fmt::layer()
.with_ansi(false)
.without_time()
.with_writer(MakeWebConsoleWriter::new());
let perf_layer = performance_layer().with_details_from_fields(Pretty::default());
tracing_subscriber::registry()
.with(fmt_layer)
.with(perf_layer)
.with(EnvFilter::from_default_env())
.init();

yew::Renderer::<App>::new().render();
}
15 changes: 14 additions & 1 deletion src/bin/worker.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
use crypto_helper::diff::{DiffTask, JsonCodec};
use tracing_subscriber::fmt::format::Pretty;
use tracing_subscriber::prelude::*;
use tracing_subscriber::EnvFilter;
use tracing_web::{performance_layer, MakeWebConsoleWriter};
use yew_agent::Registrable;

fn main() {
wasm_logger::init(wasm_logger::Config::default());
let fmt_layer = tracing_subscriber::fmt::layer()
.with_ansi(false)
.without_time()
.with_writer(MakeWebConsoleWriter::new());
let perf_layer = performance_layer().with_details_from_fields(Pretty::default());
tracing_subscriber::registry()
.with(fmt_layer)
.with(perf_layer)
.with(EnvFilter::from_default_env())
.init();

DiffTask::registrar().encoding::<JsonCodec>().register();
}
2 changes: 1 addition & 1 deletion src/jwt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ pub fn jwt() -> Html {
jwte_setter.set(Some(Jwte::Jwt(jwt)));
}
Err(err) => {
error!("Can not load JWT from local storage: {:?}", err);
error!(?err, "Can not load JWT from local storage.");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[macro_use]
extern crate log;
extern crate tracing;

mod about;
mod asn1;
Expand Down

0 comments on commit 47996f4

Please sign in to comment.