diff --git a/zenoh-jni/Cargo.lock b/zenoh-jni/Cargo.lock index 7a745e78..114ef4b3 100644 --- a/zenoh-jni/Cargo.lock +++ b/zenoh-jni/Cargo.lock @@ -140,7 +140,7 @@ dependencies = [ "log", "parking", "polling", - "rustix 0.37.25", + "rustix", "slab", "socket2 0.4.9", "waker-fn", @@ -168,7 +168,7 @@ dependencies = [ "cfg-if", "event-listener 2.5.3", "futures-lite", - "rustix 0.37.25", + "rustix", "signal-hook", "windows-sys 0.48.0", ] @@ -548,11 +548,8 @@ version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4cd405aab171cb85d6735e5c8d9db038c17d3ca007a4d2c25f337935c3d90580" dependencies = [ - "humantime", - "is-terminal", "log", "regex", - "termcolor", ] [[package]] @@ -959,17 +956,6 @@ dependencies = [ "serde", ] -[[package]] -name = "is-terminal" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" -dependencies = [ - "hermit-abi 0.3.2", - "rustix 0.38.32", - "windows-sys 0.48.0", -] - [[package]] name = "itoa" version = "1.0.9" @@ -1082,12 +1068,6 @@ version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" -[[package]] -name = "linux-raw-sys" -version = "0.4.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" - [[package]] name = "lock_api" version = "0.4.10" @@ -1781,23 +1761,10 @@ dependencies = [ "errno", "io-lifetimes", "libc", - "linux-raw-sys 0.3.8", + "linux-raw-sys", "windows-sys 0.48.0", ] -[[package]] -name = "rustix" -version = "0.38.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65e04861e65f21776e67888bfbea442b3642beaa0138fdb1dd7a84a52dffdb89" -dependencies = [ - "bitflags 2.4.0", - "errno", - "libc", - "linux-raw-sys 0.4.13", - "windows-sys 0.52.0", -] - [[package]] name = "rustls" version = "0.21.7" @@ -3495,15 +3462,15 @@ dependencies = [ "android-logd-logger", "async-std", "clap", - "env_logger", "flume 0.10.14", "jni", "json5", - "log", "rustc_version", + "tracing", "uhlc", "zenoh", "zenoh-ext", + "zenoh-util", ] [[package]] diff --git a/zenoh-jni/Cargo.toml b/zenoh-jni/Cargo.toml index 60288366..0f2c50bd 100644 --- a/zenoh-jni/Cargo.toml +++ b/zenoh-jni/Cargo.toml @@ -30,8 +30,6 @@ 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" @@ -39,7 +37,8 @@ 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"] diff --git a/zenoh-jni/src/logger.rs b/zenoh-jni/src/logger.rs index 767157c9..ffdc0be4 100644 --- a/zenoh-jni/src/logger.rs +++ b/zenoh-jni/src/logger.rs @@ -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; } diff --git a/zenoh-jni/src/publisher.rs b/zenoh-jni/src/publisher.rs index 417dad97..1f6cf54a 100644 --- a/zenoh-jni/src/publisher.rs +++ b/zenoh-jni/src/publisher.rs @@ -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 ) @@ -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())), @@ -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( @@ -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)); @@ -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 ) diff --git a/zenoh-jni/src/put.rs b/zenoh-jni/src/put.rs index 0e2cf410..e0cbbe14 100644 --- a/zenoh-jni/src/put.rs +++ b/zenoh-jni/src/put.rs @@ -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 ); @@ -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() } }; @@ -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))), diff --git a/zenoh-jni/src/query.rs b/zenoh-jni/src/query.rs index 927f2f4f..3af7122a 100644 --- a/zenoh-jni/src/query.rs +++ b/zenoh-jni/src/query.rs @@ -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; } @@ -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; } @@ -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; } @@ -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; } @@ -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 } @@ -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() @@ -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) }); } } diff --git a/zenoh-jni/src/queryable.rs b/zenoh-jni/src/queryable.rs index 60031655..ab51f4ec 100644 --- a/zenoh-jni/src/queryable.rs +++ b/zenoh-jni/src/queryable.rs @@ -89,7 +89,7 @@ pub(crate) unsafe fn declare_queryable( let session: Arc = 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| { @@ -97,15 +97,15 @@ pub(crate) unsafe fn declare_queryable( 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); diff --git a/zenoh-jni/src/reply.rs b/zenoh-jni/src/reply.rs index 3737ede4..ad5a0238 100644 --- a/zenoh-jni/src/reply.rs +++ b/zenoh-jni/src/reply.rs @@ -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 } @@ -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 } diff --git a/zenoh-jni/src/session.rs b/zenoh-jni/src/session.rs index cb4803e6..46b62791 100644 --- a/zenoh-jni/src/session.rs +++ b/zenoh-jni/src/session.rs @@ -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() } @@ -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() } @@ -190,7 +190,7 @@ 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 @@ -198,7 +198,7 @@ pub unsafe extern "C" fn Java_io_zenoh_jni_JNISession_closeSessionViaJNI( 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)); } }; } @@ -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 ) @@ -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 ) @@ -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 ) @@ -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 ) @@ -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 ) @@ -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 ) @@ -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 ) @@ -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) @@ -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:?}'", ) }) diff --git a/zenoh-jni/src/subscriber.rs b/zenoh-jni/src/subscriber.rs index 2c269608..169e5545 100644 --- a/zenoh-jni/src/subscriber.rs +++ b/zenoh-jni/src/subscriber.rs @@ -87,7 +87,7 @@ pub(crate) unsafe fn declare_subscriber( let 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 subscriber on '{}'...", key_expr); + tracing::debug!("Declaring subscriber on '{}'...", key_expr); let result = session .declare_subscriber(key_expr_clone.to_owned()) .callback(move |sample| { @@ -95,7 +95,7 @@ pub(crate) unsafe fn declare_subscriber( let mut env = match java_vm.attach_current_thread_as_daemon() { Ok(env) => env, Err(err) => { - log::error!("Unable to attach thread for subscriber: {}", err); + tracing::error!("Unable to attach thread for subscriber: {}", err); return; } }; @@ -104,7 +104,7 @@ pub(crate) unsafe fn declare_subscriber( match env.byte_array_from_slice(sample.value.payload.contiguous().as_ref()) { Ok(byte_array) => byte_array, Err(err) => { - log::error!("On subscriber callback error: {}", err.to_string()); + tracing::error!("On subscriber callback error: {}", err.to_string()); return; } }; @@ -122,7 +122,7 @@ pub(crate) unsafe fn declare_subscriber( ) { Ok(byte_array) => byte_array, Err(err) => { - log::error!( + tracing::error!( "On subscriber callback error. Error processing attachment: {}.", err.to_string() ); @@ -147,16 +147,16 @@ pub(crate) unsafe fn declare_subscriber( ) { Ok(_) => {} Err(err) => { - log::error!("On subscriber callback error: {}", err.to_string()); + tracing::error!("On subscriber callback error: {}", err.to_string()); Arc::from_raw(key_expr_ptr); // Free key expr pointer } }; _ = 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)); }) .reliability(reliability) .res(); @@ -166,7 +166,7 @@ pub(crate) unsafe fn declare_subscriber( let subscriber = result.map_err(|err| Error::Session(format!("Unable to declare subscriber: {}", err)))?; - log::debug!( + tracing::debug!( "Subscriber declared on '{}' with reliability '{:?}'.", key_expr_clone, reliability, diff --git a/zenoh-jni/src/utils.rs b/zenoh-jni/src/utils.rs index 71eebaf1..963f93ff 100644 --- a/zenoh-jni/src/utils.rs +++ b/zenoh-jni/src/utils.rs @@ -94,7 +94,7 @@ pub(crate) fn load_on_close( let mut env = match java_vm.attach_current_thread_as_daemon() { Ok(env) => env, Err(err) => { - log::error!("Unable to attach thread for 'onClose' callback: {}", err); + tracing::error!("Unable to attach thread for 'onClose' callback: {}", err); return; } }; @@ -105,7 +105,10 @@ pub(crate) fn load_on_close( _ = Error::Jni(format!("Error while running 'onClose' callback: {}", err)) .throw_on_jvm(&mut env) .map_err(|err| { - log::error!("Unable to throw exception upon 'onClose' failure: {}", err) + tracing::error!( + "Unable to throw exception upon 'onClose' failure: {}", + err + ) }); } } diff --git a/zenoh-jni/src/value.rs b/zenoh-jni/src/value.rs index d4fa030e..d3f27b9e 100644 --- a/zenoh-jni/src/value.rs +++ b/zenoh-jni/src/value.rs @@ -32,7 +32,7 @@ pub(crate) fn decode_value(env: &JNIEnv<'_>, payload: JByteArray, encoding: i32) let encoding = match KnownEncoding::try_from(encoding as u8) { Ok(encoding) => encoding, Err(_) => { - log::debug!("Unable to retrieve encoding. Setting Empty encoding."); + tracing::debug!("Unable to retrieve encoding. Setting Empty encoding."); KnownEncoding::Empty } };