Skip to content

Commit

Permalink
Merge pull request #58 from eclipse-zenoh/feat/tracing
Browse files Browse the repository at this point in the history
feat(tracing): using tracing instead of log
  • Loading branch information
gabrik authored Apr 15, 2024
2 parents df701d9 + 1b7a257 commit af8b3c7
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 97 deletions.
43 changes: 5 additions & 38 deletions zenoh-jni/Cargo.lock

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

5 changes: 2 additions & 3 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.7.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-util = { version = "0.11.0-dev", git = "https://github.com/eclipse-zenoh/zenoh.git", branch = "main" }
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
10 changes: 5 additions & 5 deletions zenoh-jni/src/publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,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 @@ -145,7 +145,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 @@ -215,7 +215,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 @@ -258,7 +258,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 @@ -320,7 +320,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
}
Loading

0 comments on commit af8b3c7

Please sign in to comment.