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

deps: replace log with tracing #525

Merged
merged 1 commit into from
Oct 15, 2021
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
3 changes: 2 additions & 1 deletion examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ publish = false
anyhow = "1"
env_logger = "0.9"
jsonrpsee = { path = "../jsonrpsee", features = ["full"] }
log = "0.4"
tracing = "0.1"
tracing-subscriber = "0.2"
tokio = { version = "1", features = ["full"] }

[[example]]
Expand Down
6 changes: 4 additions & 2 deletions examples/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,17 @@ use std::net::SocketAddr;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
env_logger::init();
// init tracing `FmtSubscriber`.
let subscriber = tracing_subscriber::FmtSubscriber::new();
tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed");

let (server_addr, _handle) = run_server().await?;
let url = format!("http://{}", server_addr);

let client = HttpClientBuilder::default().build(url)?;
let params = rpc_params!(1_u64, 2, 3);
let response: Result<String, _> = client.request("say_hello", params).await;
println!("r: {:?}", response);
tracing::info!("r: {:?}", response);

Ok(())
}
Expand Down
4 changes: 3 additions & 1 deletion examples/proc_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ impl RpcServer<ExampleHash, ExampleStorageKey> for RpcServerImpl {

#[tokio::main]
async fn main() -> anyhow::Result<()> {
env_logger::init();
// init tracing `FmtSubscriber`.
let subscriber = tracing_subscriber::FmtSubscriber::builder().finish();
tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed");

let (server_addr, _handle) = run_server().await?;
let url = format!("ws://{}", server_addr);
Expand Down
7 changes: 5 additions & 2 deletions examples/ws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,16 @@ use std::net::SocketAddr;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
env_logger::init();
// init tracing `FmtSubscriber`.
let subscriber = tracing_subscriber::FmtSubscriber::builder().finish();
tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed");

let addr = run_server().await?;
let url = format!("ws://{}", addr);

let client = WsClientBuilder::default().build(&url).await?;
let response: String = client.request("say_hello", None).await?;
println!("r: {:?}", response);
tracing::info!("response: {:?}", response);

Ok(())
}
Expand Down
9 changes: 6 additions & 3 deletions examples/ws_sub_with_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ use std::net::SocketAddr;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
env_logger::init();
// init tracing `FmtSubscriber`.
let subscriber = tracing_subscriber::FmtSubscriber::builder().finish();
tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed");

let addr = run_server().await?;
let url = format!("ws://{}", addr);

Expand All @@ -43,12 +46,12 @@ async fn main() -> anyhow::Result<()> {
// Subscription with a single parameter
let mut sub_params_one =
client.subscribe::<Option<char>>("sub_one_param", rpc_params![3], "unsub_one_param").await?;
println!("subscription with one param: {:?}", sub_params_one.next().await);
tracing::info!("subscription with one param: {:?}", sub_params_one.next().await);

// Subscription with multiple parameters
let mut sub_params_two =
client.subscribe::<String>("sub_params_two", rpc_params![2, 5], "unsub_params_two").await?;
println!("subscription with two params: {:?}", sub_params_two.next().await);
tracing::info!("subscription with two params: {:?}", sub_params_two.next().await);

Ok(())
}
Expand Down
10 changes: 7 additions & 3 deletions examples/ws_subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,14 @@ use jsonrpsee::{
};
use std::net::SocketAddr;

const NUM_SUBSCRIPTION_RESPONSES: usize = 5;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
const NUM_SUBSCRIPTION_RESPONSES: usize = 5;
env_logger::init();
// init tracing `FmtSubscriber`.
let subscriber = tracing_subscriber::FmtSubscriber::builder().finish();
tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed");

let addr = run_server().await?;
let url = format!("ws://{}", addr);

Expand All @@ -46,7 +50,7 @@ async fn main() -> anyhow::Result<()> {
let mut i = 0;
while i <= NUM_SUBSCRIPTION_RESPONSES {
let r = subscribe_hello.next().await;
println!("received {:?}", r);
tracing::info!("received {:?}", r);
i += 1;
}

Expand Down
2 changes: 1 addition & 1 deletion http-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ hyper-rustls = "0.22"
hyper = { version = "0.14.10", features = ["client", "http1", "http2", "tcp"] }
jsonrpsee-types = { path = "../types", version = "0.4.1" }
jsonrpsee-utils = { path = "../utils", version = "0.4.1", features = ["http-helpers"] }
log = "0.4"
tracing = "0.1"
serde = { version = "1.0", default-features = false, features = ["derive"] }
serde_json = "1.0"
tokio = { version = "1", features = ["time"] }
Expand Down
2 changes: 1 addition & 1 deletion http-client/src/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl HttpTransportClient {
}

async fn inner_send(&self, body: String) -> Result<hyper::Response<hyper::Body>, Error> {
log::debug!("send: {}", body);
tracing::debug!("send: {}", body);

if body.len() > self.max_request_body_size as usize {
return Err(Error::RequestTooLarge);
Expand Down
2 changes: 1 addition & 1 deletion http-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jsonrpsee-types = { path = "../types", version = "0.4.1" }
jsonrpsee-utils = { path = "../utils", version = "0.4.1", features = ["server", "http-helpers"] }
globset = "0.4"
lazy_static = "1.4"
log = "0.4"
tracing = "0.1"
serde_json = "1"
socket2 = "0.4"
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
Expand Down
2 changes: 1 addition & 1 deletion http-server/src/access_control/matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
// DEALINGS IN THE SOFTWARE.

use globset::{GlobBuilder, GlobMatcher};
use log::warn;
use std::{fmt, hash};
use tracing::warn;

/// Pattern that can be matched to string.
pub(crate) trait Pattern {
Expand Down
4 changes: 2 additions & 2 deletions http-server/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ impl Server {
Err(GenericTransportError::TooLarge) => return Ok::<_, HyperError>(response::too_large()),
Err(GenericTransportError::Malformed) => return Ok::<_, HyperError>(response::malformed()),
Err(GenericTransportError::Inner(e)) => {
log::error!("Internal error reading request body: {}", e);
tracing::error!("Internal error reading request body: {}", e);
return Ok::<_, HyperError>(response::internal_error());
}
};
Expand Down Expand Up @@ -281,7 +281,7 @@ impl Server {
} else {
collect_batch_response(rx).await
};
log::debug!("[service_fn] sending back: {:?}", &response[..cmp::min(response.len(), 1024)]);
tracing::debug!("[service_fn] sending back: {:?}", &response[..cmp::min(response.len(), 1024)]);
Ok::<_, HyperError>(response::ok_response(response))
}
}))
Expand Down
2 changes: 1 addition & 1 deletion proc-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ proc-macro2 = "1.0"
quote = "1.0"
syn = { version = "1.0", default-features = false, features = ["extra-traits", "full", "visit", "parsing"] }
proc-macro-crate = "1"
log = "0.4"
tracing = "0.1"

[dev-dependencies]
jsonrpsee = { path = "../jsonrpsee", features = ["full"] }
Expand Down
4 changes: 2 additions & 2 deletions proc-macros/src/render_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ impl RpcDescription {
let #name: #ty = match seq.optional_next() {
Ok(v) => v,
Err(e) => {
log::error!(concat!("Error parsing optional \"", stringify!(#name), "\" as \"", stringify!(#ty), "\": {:?}"), e);
tracing::error!(concat!("Error parsing optional \"", stringify!(#name), "\" as \"", stringify!(#ty), "\": {:?}"), e);
return Err(e.into())
}
};
Expand All @@ -302,7 +302,7 @@ impl RpcDescription {
let #name: #ty = match seq.next() {
Ok(v) => v,
Err(e) => {
log::error!(concat!("Error parsing \"", stringify!(#name), "\" as \"", stringify!(#ty), "\": {:?}"), e);
tracing::error!(concat!("Error parsing \"", stringify!(#name), "\" as \"", stringify!(#ty), "\": {:?}"), e);
return Err(e.into())
}
};
Expand Down
2 changes: 1 addition & 1 deletion test-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ anyhow = "1"
futures-channel = "0.3.14"
futures-util = "0.3.14"
hyper = { version = "0.14.10", features = ["full"] }
log = "0.4"
tracing = "0.1"
serde = { version = "1", default-features = false, features = ["derive"] }
serde_json = "1"
soketto = { version = "0.7", features = ["http"] }
Expand Down
10 changes: 5 additions & 5 deletions test-utils/src/mocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,12 @@ async fn connection_task(socket: tokio::net::TcpStream, mode: ServerMode, mut ex
match &mode {
ServerMode::Subscription { subscription_response, .. } => {
if let Err(e) = sender.send_text(&subscription_response).await {
log::warn!("send response to subscription: {:?}", e);
tracing::warn!("send response to subscription: {:?}", e);
}
},
ServerMode::Notification(n) => {
if let Err(e) = sender.send_text(&n).await {
log::warn!("send notification: {:?}", e);
tracing::warn!("send notification: {:?}", e);
}
},
_ => {}
Expand All @@ -296,12 +296,12 @@ async fn connection_task(socket: tokio::net::TcpStream, mode: ServerMode, mut ex
match &mode {
ServerMode::Response(r) => {
if let Err(e) = sender.send_text(&r).await {
log::warn!("send response to request error: {:?}", e);
tracing::warn!("send response to request error: {:?}", e);
}
},
ServerMode::Subscription { subscription_id, .. } => {
if let Err(e) = sender.send_text(&subscription_id).await {
log::warn!("send subscription id error: {:?}", e);
tracing::warn!("send subscription id error: {:?}", e);
}
},
_ => {}
Expand Down Expand Up @@ -340,7 +340,7 @@ async fn handler(
other_server: String,
) -> Result<hyper::Response<Body>, soketto::BoxedError> {
if is_upgrade_request(&req) {
log::debug!("{:?}", req);
tracing::debug!("{:?}", req);

match req.uri().path() {
"/myblock/two" => {
Expand Down
2 changes: 1 addition & 1 deletion tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ futures = { version = "0.3.14", default-features = false, features = ["std"] }
jsonrpsee = { path = "../jsonrpsee", features = ["full"] }
tokio = { version = "1", features = ["full"] }
serde_json = "1"
log = "0.4"
tracing = "0.1"
2 changes: 1 addition & 1 deletion types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ anyhow = "1"
beef = { version = "0.5.1", features = ["impl_serde"] }
futures-channel = { version = "0.3.14", features = ["sink"] }
futures-util = { version = "0.3.14", default-features = false, features = ["std", "sink", "channel"] }
log = { version = "0.4", default-features = false }
tracing = { version = "0.1", default-features = false }
serde = { version = "1", default-features = false, features = ["derive"] }
serde_json = { version = "1", default-features = false, features = ["alloc", "raw_value", "std"] }
thiserror = "1.0"
Expand Down
8 changes: 4 additions & 4 deletions types/src/v2/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,18 @@ impl<'a> ParamsSequence<'a> {
T: Deserialize<'a>,
{
let mut json = self.0;
log::trace!("[next_inner] Params JSON: {:?}", json);
tracing::trace!("[next_inner] Params JSON: {:?}", json);
match json.as_bytes().get(0)? {
b']' => {
self.0 = "";

log::trace!("[next_inner] Reached end of sequence.");
tracing::trace!("[next_inner] Reached end of sequence.");
return None;
}
b'[' | b',' => json = &json[1..],
_ => {
let errmsg = format!("Invalid params. Expected one of '[', ']' or ',' but found {:?}", json);
log::error!("[next_inner] {}", errmsg);
tracing::error!("[next_inner] {}", errmsg);
return Some(Err(CallError::InvalidParams(anyhow!(errmsg))));
}
}
Expand All @@ -183,7 +183,7 @@ impl<'a> ParamsSequence<'a> {
Some(Ok(value))
}
Err(e) => {
log::error!(
tracing::error!(
"[next_inner] Deserialization to {:?} failed. Error: {:?}, input JSON: {:?}",
std::any::type_name::<T>(),
e,
Expand Down
4 changes: 2 additions & 2 deletions utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ futures-channel = { version = "0.3.14", default-features = false, optional = tru
futures-util = { version = "0.3.14", default-features = false, optional = true }
hyper = { version = "0.14.10", default-features = false, features = ["stream"], optional = true }
jsonrpsee-types = { path = "../types", version = "0.4.1", optional = true }
log = { version = "0.4", optional = true }
tracing = { version = "0.1", optional = true }
rustc-hash = { version = "1", optional = true }
rand = { version = "0.8", optional = true }
serde = { version = "1.0", default-features = false, features = ["derive"], optional = true }
Expand All @@ -32,7 +32,7 @@ server = [
"rustc-hash",
"serde",
"serde_json",
"log",
"tracing",
"parking_lot",
"rand",
]
Expand Down
8 changes: 4 additions & 4 deletions utils/src/server/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ pub fn send_response(id: Id, tx: &MethodSink, result: impl Serialize) {
let json = match serde_json::to_string(&Response { jsonrpc: TwoPointZero, id: id.clone(), result }) {
Ok(json) => json,
Err(err) => {
log::error!("Error serializing response: {:?}", err);
tracing::error!("Error serializing response: {:?}", err);

return send_error(id, tx, ErrorCode::InternalError.into());
}
};

if let Err(err) = tx.unbounded_send(json) {
log::error!("Error sending response to the client: {:?}", err)
tracing::error!("Error sending response to the client: {:?}", err)
}
}

Expand All @@ -55,14 +55,14 @@ pub fn send_error(id: Id, tx: &MethodSink, error: ErrorObject) {
let json = match serde_json::to_string(&RpcError { jsonrpc: TwoPointZero, error, id }) {
Ok(json) => json,
Err(err) => {
log::error!("Error serializing error message: {:?}", err);
tracing::error!("Error serializing error message: {:?}", err);

return;
}
};

if let Err(err) = tx.unbounded_send(json) {
log::error!("Could not send error response to the client: {:?}", err)
tracing::error!("Could not send error response to the client: {:?}", err)
}
}

Expand Down
Loading