Skip to content

Commit

Permalink
feat(tracing): using tracing instead of log
Browse files Browse the repository at this point in the history
Signed-off-by: gabrik <[email protected]>
  • Loading branch information
gabrik committed Apr 3, 2024
1 parent 352a2f6 commit a6b0007
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 62 deletions.
9 changes: 4 additions & 5 deletions zenoh-jni/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,15 @@ default = ["zenoh/default", "zenoh-ext/default"]
[dependencies]
android-logd-logger = "0.4.0"
async-std = { version = "=1.12.0", default-features = false }
log = "0.4.17"
env_logger = "0.10.0"
clap = "3.2.23"
jni = "0.21.1"
flume = "0.10.14"
uhlc = "0.6.0"
json5 = "0.4.1"
zenoh = { version = "0.11.0-dev", git = "https://github.com/eclipse-zenoh/zenoh.git", branch = "main", default-features = false }
zenoh-ext = { version = "0.11.0-dev", git = "https://github.com/eclipse-zenoh/zenoh.git", branch = "main", default-features = false }

zenoh = { version = "0.11.0-dev", git = "https://github.com/eclipse-zenoh/zenoh.git", branch = "feat/tracing", default-features = false }
zenoh-ext = { version = "0.11.0-dev", git = "https://github.com/eclipse-zenoh/zenoh.git", branch = "feat/tracing", default-features = false }
zenoh-util = { version = "0.11.0-dev", git = "https://github.com/eclipse-zenoh/zenoh.git", branch = "feat/tracing" }
tracing = "0.1"
[lib]
name = "zenoh_jni"
crate_type = ["staticlib", "dylib"]
Expand Down
2 changes: 1 addition & 1 deletion zenoh-jni/src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub extern "C" fn Java_io_zenoh_Logger_00024Companion_start(
Ok(level) => level,
Err(err) => {
_ = err.throw_on_jvm(&mut env).map_err(|err| {
log::error!("Error throwing exception on log start failure! {}", err)
tracing::error!("Error throwing exception on log start failure! {}", err)
});
return;
}
Expand Down
12 changes: 6 additions & 6 deletions zenoh-jni/src/publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub unsafe extern "C" fn Java_io_zenoh_jni_JNIPublisher_putViaJNI(
Ok(_) => {}
Err(err) => {
_ = err.throw_on_jvm(&mut env).map_err(|err| {
log::error!(
tracing::error!(
"Unable to throw exception on PUT operation failure: {}",
err
)
Expand Down Expand Up @@ -146,7 +146,7 @@ pub(crate) unsafe fn declare_publisher(
std::mem::forget(key_expr);
match result {
Ok(publisher) => {
log::trace!("Declared publisher ok key expr '{key_expr_clone}', with congestion control '{congestion_control:?}', priority '{priority:?}'.");
tracing::trace!("Declared publisher ok key expr '{key_expr_clone}', with congestion control '{congestion_control:?}', priority '{priority:?}'.");
Ok(Arc::into_raw(Arc::new(publisher)))
}
Err(err) => Err(Error::Session(err.to_string())),
Expand Down Expand Up @@ -216,7 +216,7 @@ pub unsafe extern "C" fn Java_io_zenoh_jni_JNIPublisher_setCongestionControlViaJ
return;
}
};
log::debug!("Setting publisher congestion control with '{congestion_control:?}'.");
tracing::debug!("Setting publisher congestion control with '{congestion_control:?}'.");
unsafe {
let publisher = core::ptr::read(ptr);
core::ptr::write(
Expand Down Expand Up @@ -259,7 +259,7 @@ pub unsafe extern "C" fn Java_io_zenoh_jni_JNIPublisher_setPriorityViaJNI(
return;
}
};
log::debug!("Setting publisher priority with '{priority:?}'.");
tracing::debug!("Setting publisher priority with '{priority:?}'.");
unsafe {
let publisher = core::ptr::read(ptr);
core::ptr::write(ptr as *mut _, publisher.priority(priority));
Expand Down Expand Up @@ -342,7 +342,7 @@ pub unsafe extern "C" fn Java_io_zenoh_jni_JNIPublisher_writeViaJNI(
Ok(_) => {}
Err(err) => {
_ = err.throw_on_jvm(&mut env).map_err(|err| {
log::error!(
tracing::error!(
"Unable to throw exception on WRITE operation failure: {}",
err
)
Expand Down Expand Up @@ -407,7 +407,7 @@ pub unsafe extern "C" fn Java_io_zenoh_jni_JNIPublisher_deleteViaJNI(
Ok(_) => {}
Err(err) => {
_ = err.throw_on_jvm(&mut env).map_err(|err| {
log::error!(
tracing::error!(
"Unable to throw exception on WRITE operation failure: {}",
err
)
Expand Down
6 changes: 3 additions & 3 deletions zenoh-jni/src/put.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub(crate) fn on_put(
let congestion_control = match decode_congestion_control(congestion_control) {
Ok(congestion_control) => congestion_control,
Err(err) => {
log::warn!(
tracing::warn!(
"Error decoding congestion control: '{}'. Using default...",
err
);
Expand All @@ -68,7 +68,7 @@ pub(crate) fn on_put(
let priority = match decode_priority(priority) {
Ok(priority) => priority,
Err(err) => {
log::warn!("Error decoding priority: '{}'. Using default...", err);
tracing::warn!("Error decoding priority: '{}'. Using default...", err);
Priority::default()
}
};
Expand All @@ -88,7 +88,7 @@ pub(crate) fn on_put(

match put_builder.res() {
Ok(_) => {
log::trace!("Put on '{key_expr}' with value '{value}' and encoding '{}'. Kind: '{sample_kind}', Congestion control: '{congestion_control:?}', Priority: '{priority:?}'", value.encoding);
tracing::trace!("Put on '{key_expr}' with value '{value}' and encoding '{}'. Kind: '{sample_kind}', Congestion control: '{congestion_control:?}', Priority: '{priority:?}'", value.encoding);
Ok(())
}
Err(err) => Err(Error::Session(format!("{}", err))),
Expand Down
18 changes: 9 additions & 9 deletions zenoh-jni/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub(crate) unsafe extern "C" fn Java_io_zenoh_jni_JNIQuery_replySuccessViaJNI(
Ok(sample) => sample,
Err(err) => {
_ = err.throw_on_jvm(&mut env).map_err(|err| {
log::error!("Unable to throw exception on query reply failure. {}", err)
tracing::error!("Unable to throw exception on query reply failure. {}", err)
});
return;
}
Expand All @@ -98,7 +98,7 @@ pub(crate) unsafe extern "C" fn Java_io_zenoh_jni_JNIQuery_replySuccessViaJNI(
Ok(attachment_bytes) => Some(vec_to_attachment(attachment_bytes)),
Err(err) => {
_ = err.throw_on_jvm(&mut env).map_err(|err| {
log::error!("Unable to throw exception on query reply failure. {}", err)
tracing::error!("Unable to throw exception on query reply failure. {}", err)
});
return;
}
Expand Down Expand Up @@ -150,7 +150,7 @@ pub(crate) unsafe extern "C" fn Java_io_zenoh_jni_JNIQuery_replyErrorViaJNI(
Ok(value) => value,
Err(err) => {
_ = err.throw_on_jvm(&mut env).map_err(|err| {
log::error!("Unable to throw exception on query reply failure. {}", err)
tracing::error!("Unable to throw exception on query reply failure. {}", err)
});
return;
}
Expand All @@ -160,7 +160,7 @@ pub(crate) unsafe extern "C" fn Java_io_zenoh_jni_JNIQuery_replyErrorViaJNI(
Ok(attachment_bytes) => Some(vec_to_attachment(attachment_bytes)),
Err(err) => {
_ = err.throw_on_jvm(&mut env).map_err(|err| {
log::error!("Unable to throw exception on query reply failure. {}", err)
tracing::error!("Unable to throw exception on query reply failure. {}", err)
});
return;
}
Expand Down Expand Up @@ -289,13 +289,13 @@ pub(crate) fn on_query(

_ = env
.delete_local_ref(selector_params_jstr)
.map_err(|err| log::error!("Error deleting local ref: {}", err));
.map_err(|err| tracing::error!("Error deleting local ref: {}", err));
_ = env
.delete_local_ref(payload)
.map_err(|err| log::error!("Error deleting local ref: {}", err));
.map_err(|err| tracing::error!("Error deleting local ref: {}", err));
_ = env
.delete_local_ref(attachment_bytes)
.map_err(|err| log::error!("Error deleting local ref: {}", err));
.map_err(|err| tracing::error!("Error deleting local ref: {}", err));
result
}

Expand All @@ -311,7 +311,7 @@ fn query_reply(
.reply(reply)
.with_attachment(attachment)
.unwrap_or_else(|(builder, _)| {
log::warn!("Unable to append attachment to query reply");
tracing::warn!("Unable to append attachment to query reply");
builder
})
.res()
Expand All @@ -326,7 +326,7 @@ fn query_reply(
Ok(_) => {}
Err(err) => {
_ = err.throw_on_jvm(&mut env).map_err(|err| {
log::error!("Unable to throw exception on query reply failure. {}", err)
tracing::error!("Unable to throw exception on query reply failure. {}", err)
});
}
}
Expand Down
10 changes: 5 additions & 5 deletions zenoh-jni/src/queryable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,23 +89,23 @@ pub(crate) unsafe fn declare_queryable(
let session: Arc<Session> = Arc::from_raw(session_ptr);
let key_expr = Arc::from_raw(key_expr_ptr);
let key_expr_clone = key_expr.deref().clone();
log::debug!("Declaring queryable through JNI on {}", key_expr);
tracing::debug!("Declaring queryable through JNI on {}", key_expr);
let queryable = session
.declare_queryable(key_expr_clone)
.callback(move |query| {
on_close.noop(); // Does nothing, but moves `on_close` inside the closure so it gets destroyed with the closure
let env = match java_vm.attach_current_thread_as_daemon() {
Ok(env) => env,
Err(err) => {
log::error!("Unable to attach thread for queryable callback: {}", err);
tracing::error!("Unable to attach thread for queryable callback: {}", err);
return;
}
};

log::debug!("Receiving query through JNI: {}", query.to_string());
tracing::debug!("Receiving query through JNI: {}", query.to_string());
match on_query(env, query, &callback_global_ref) {
Ok(_) => log::debug!("Queryable callback called successfully."),
Err(err) => log::error!("Error calling queryable callback: {}", err),
Ok(_) => tracing::debug!("Queryable callback called successfully."),
Err(err) => tracing::error!("Error calling queryable callback: {}", err),
}
})
.complete(complete);
Expand Down
10 changes: 5 additions & 5 deletions zenoh-jni/src/reply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ fn on_reply_success(

_ = env
.delete_local_ref(zenoh_id)
.map_err(|err| log::debug!("Error deleting local ref: {}", err));
.map_err(|err| tracing::debug!("Error deleting local ref: {}", err));
_ = env
.delete_local_ref(byte_array)
.map_err(|err| log::debug!("Error deleting local ref: {}", err));
.map_err(|err| tracing::debug!("Error deleting local ref: {}", err));
_ = env
.delete_local_ref(attachment_bytes)
.map_err(|err| log::debug!("Error deleting local ref: {}", err));
.map_err(|err| tracing::debug!("Error deleting local ref: {}", err));
result
}

Expand Down Expand Up @@ -148,9 +148,9 @@ fn on_reply_error(

_ = env
.delete_local_ref(zenoh_id)
.map_err(|err| log::debug!("Error deleting local ref: {}", err));
.map_err(|err| tracing::debug!("Error deleting local ref: {}", err));
_ = env
.delete_local_ref(byte_array)
.map_err(|err| log::debug!("Error deleting local ref: {}", err));
.map_err(|err| tracing::debug!("Error deleting local ref: {}", err));
result
}
34 changes: 17 additions & 17 deletions zenoh-jni/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ pub extern "C" fn Java_io_zenoh_jni_JNISession_openSessionViaJNI(
match session {
Ok(session) => Arc::into_raw(Arc::new(session)),
Err(err) => {
log::error!("Unable to open session: {}", err);
tracing::error!("Unable to open session: {}", err);
_ = Error::Session(err.to_string())
.throw_on_jvm(&mut env)
.map_err(|err| {
log::error!("Unable to throw exception on session failure: {}", err)
tracing::error!("Unable to throw exception on session failure: {}", err)
});
null()
}
Expand Down Expand Up @@ -100,11 +100,11 @@ pub extern "C" fn Java_io_zenoh_jni_JNISession_openSessionWithJsonConfigViaJNI(
match session {
Ok(session) => Arc::into_raw(Arc::new(session)),
Err(err) => {
log::error!("Unable to open session: {}", err);
tracing::error!("Unable to open session: {}", err);
_ = Error::Session(err.to_string())
.throw_on_jvm(&mut env)
.map_err(|err| {
log::error!("Unable to throw exception on session failure: {}", err)
tracing::error!("Unable to throw exception on session failure: {}", err)
});
null()
}
Expand Down Expand Up @@ -190,15 +190,15 @@ pub unsafe extern "C" fn Java_io_zenoh_jni_JNISession_closeSessionViaJNI(
}
Err(arc_session) => {
let ref_count = Arc::strong_count(&arc_session);
log::error!("Unable to close the session.");
tracing::error!("Unable to close the session.");
_ = Error::Session(format!(
"Attempted to close the session, but at least one strong reference to it is still alive
(ref count: {}). All the declared publishers, subscribers, and queryables need to be
dropped first.",
ref_count
))
.throw_on_jvm(&mut env)
.map_err(|err| log::error!("Unable to throw exception on session failure: {}", err));
.map_err(|err| tracing::error!("Unable to throw exception on session failure: {}", err));
}
};
}
Expand Down Expand Up @@ -241,7 +241,7 @@ pub unsafe extern "C" fn Java_io_zenoh_jni_JNISession_declarePublisherViaJNI(
Ok(ptr) => ptr,
Err(err) => {
_ = err.throw_on_jvm(&mut env).map_err(|err| {
log::error!(
tracing::error!(
"Unable to throw exception on publisher declaration failure. {}",
err
)
Expand Down Expand Up @@ -305,7 +305,7 @@ pub unsafe extern "C" fn Java_io_zenoh_jni_JNISession_putViaJNI(
Ok(_) => {}
Err(err) => {
_ = err.throw_on_jvm(&mut env).map_err(|err| {
log::error!(
tracing::error!(
"Unable to throw exception on query declaration failure. {}",
err
)
Expand Down Expand Up @@ -356,7 +356,7 @@ pub unsafe extern "C" fn Java_io_zenoh_jni_JNISession_declareSubscriberViaJNI(
Ok(subscriber_ptr) => subscriber_ptr,
Err(err) => {
_ = err.throw_on_jvm(&mut env).map_err(|err| {
log::error!(
tracing::error!(
"Unable to throw exception on subscriber declaration failure: {}",
err
)
Expand Down Expand Up @@ -413,7 +413,7 @@ pub unsafe extern "C" fn Java_io_zenoh_jni_JNISession_declareQueryableViaJNI(
Ok(queryable) => Arc::into_raw(Arc::new(queryable)),
Err(err) => {
_ = err.throw_on_jvm(&mut env).map_err(|err| {
log::error!(
tracing::error!(
"Unable to throw exception on query declaration failure. {}",
err
)
Expand Down Expand Up @@ -455,7 +455,7 @@ pub unsafe extern "C" fn Java_io_zenoh_jni_JNISession_declareKeyExprViaJNI(
Ok(key_expr) => Arc::into_raw(Arc::new(key_expr)),
Err(err) => {
_ = err.throw_on_jvm(&mut env).map_err(|err| {
log::error!(
tracing::error!(
"Unable to throw exception on key expr declaration failure. {}",
err
)
Expand Down Expand Up @@ -571,7 +571,7 @@ pub unsafe extern "C" fn Java_io_zenoh_jni_JNISession_getViaJNI(
Ok(_) => {}
Err(err) => {
_ = err.throw_on_jvm(&mut env).map_err(|err| {
log::error!(
tracing::error!(
"Unable to throw exception on get operation failure. {}",
err
)
Expand Down Expand Up @@ -646,7 +646,7 @@ pub unsafe extern "C" fn Java_io_zenoh_jni_JNISession_getWithValueViaJNI(
Ok(_) => {}
Err(err) => {
_ = err.throw_on_jvm(&mut env).map_err(|err| {
log::error!(
tracing::error!(
"Unable to throw exception on get operation failure. {}",
err
)
Expand Down Expand Up @@ -705,17 +705,17 @@ fn on_get_query(
.get(selector)
.callback(move |reply| {
on_close.noop(); // Does nothing, but moves `on_close` inside the closure so it gets destroyed with the closure
log::debug!("Receiving reply through JNI: {:?}", reply);
tracing::debug!("Receiving reply through JNI: {:?}", reply);
let env = match java_vm.attach_current_thread_as_daemon() {
Ok(env) => env,
Err(err) => {
log::error!("Unable to attach thread for GET query callback: {}", err);
tracing::error!("Unable to attach thread for GET query callback: {}", err);
return;
}
};
match on_reply(env, reply, &callback_global_ref) {
Ok(_) => {}
Err(err) => log::error!("{}", err),
Err(err) => tracing::error!("{}", err),
}
})
.target(query_target)
Expand All @@ -738,7 +738,7 @@ fn on_get_query(
get_builder
.res()
.map(|_| {
log::trace!(
tracing::trace!(
"Performing get on {key_expr:?}, with target '{query_target:?}', with timeout '{timeout:?}', consolidation '{consolidation:?}', with value: '{binding:?}'",
)
})
Expand Down
Loading

0 comments on commit a6b0007

Please sign in to comment.