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

feat: update println! and eprintln! to info using tracing cargo. #1309

Merged
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: 2 additions & 0 deletions roles/Cargo.lock

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

2 changes: 2 additions & 0 deletions roles/test-utils/mining-device-sv1/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ serde_json = { version = "1.0.64", default-features = false, features = ["alloc"
v1 = { path="../../../protocols/v1", package="sv1_api" }
num-bigint = "0.4.3"
num-traits = "0.2.15"
tracing = "0.1.41"
tracing-subscriber = "0.3.19"
11 changes: 6 additions & 5 deletions roles/test-utils/mining-device-sv1/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use num_bigint::BigUint;
use num_traits::FromPrimitive;
use roles_logic_sv2::utils::Mutex;
use std::{sync::Arc, time};
use tracing::{error, info, warn};

use stratum_common::bitcoin::util::uint::Uint256;
use v1::{
Expand Down Expand Up @@ -105,17 +106,17 @@ impl Client {
match message {
Ok(msg) => {
if let Err(e) = sender_incoming.send(msg).await {
eprintln!("Failed to send message to receiver_incoming: {:?}", e);
error!("Failed to send message to receiver_incoming: {:?}", e);
break; // Exit the loop if sending fails
}
}
Err(e) => {
eprintln!("Error reading from socket: {:?}", e);
error!("Error reading from socket: {:?}", e);
break; // Exit the loop on read failure
}
}
}
eprintln!("Reader task terminated.");
warn!("Reader task terminated.");
});

// Waits to receive a message from `sender_outgoing` and writes it to the socket for the
Expand Down Expand Up @@ -234,7 +235,7 @@ impl Client {
) {
// If we have a line (1 line represents 1 sv1 incoming message), then handle that message
if let Ok(line) = incoming_message {
println!(
info!(
"CLIENT {} - Received: {}",
self_.safe_lock(|s| s.client_id).unwrap(),
line
Expand All @@ -254,7 +255,7 @@ impl Client {
/// Send SV1 messages to the receiver_outgoing which writes to the socket (aka Upstream node)
async fn send_message(sender: Sender<String>, msg: json_rpc::Message) {
let msg = format!("{}\n", serde_json::to_string(&msg).unwrap());
println!(" - Send: {}", &msg);
info!(" - Send: {}", &msg);
sender.send(msg).await.unwrap();
}

Expand Down
2 changes: 2 additions & 0 deletions roles/test-utils/mining-device-sv1/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ pub(crate) use client::Client;

#[async_std::main]
async fn main() {
tracing_subscriber::fmt().init();

const ADDR: &str = "127.0.0.1:34255";
Client::connect(
80,
Expand Down
3 changes: 2 additions & 1 deletion roles/test-utils/mining-device-sv1/src/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
hashes::{sha256d::Hash as DHash, Hash},
util::uint::Uint256,
};
use tracing::info;

/// A mock representation of a Mining Device that produces block header hashes to be submitted by
/// the `Client` to the Upstream node (either a SV1 Pool server or a SV1 <-> SV2 Translator Proxy
Expand Down Expand Up @@ -75,7 +76,7 @@
hash.reverse();
let hash = Uint256::from_be_bytes(hash);
if hash < *self.target.as_ref().ok_or(())? {
println!(
info!(

Check warning on line 79 in roles/test-utils/mining-device-sv1/src/miner.rs

View check run for this annotation

Codecov / codecov/patch

roles/test-utils/mining-device-sv1/src/miner.rs#L79

Added line #L79 was not covered by tests
"Found share with nonce: {}, for target: {:?}, hash: {:?}",
header.nonce, self.target, hash
);
Expand Down
Loading