From 861c551eba7e644ffe5d6b0585f26fe5fa23522d Mon Sep 17 00:00:00 2001 From: Bugen Zhao Date: Wed, 20 Dec 2023 17:58:43 +0800 Subject: [PATCH] use `execute_and_catch` Signed-off-by: Bugen Zhao --- src/jni_core/src/tracing_slf4j.rs | 64 +++++++++++++++---------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/src/jni_core/src/tracing_slf4j.rs b/src/jni_core/src/tracing_slf4j.rs index ccb0c7bbbc2a5..ce410b9bcb001 100644 --- a/src/jni_core/src/tracing_slf4j.rs +++ b/src/jni_core/src/tracing_slf4j.rs @@ -18,43 +18,43 @@ use jni::objects::JString; use jni::sys::jint; use tracing::Level; -use crate::EnvParam; +use crate::{execute_and_catch, EnvParam}; #[no_mangle] pub(crate) extern "system" fn Java_com_risingwave_java_binding_Binding_tracingSlf4jEvent( - mut env: EnvParam<'_>, + env: EnvParam<'_>, class_name: JString<'_>, level: jint, message: JString<'_>, ) { - let Ok(class_name) = env.get_string(&class_name) else { - return; - }; - let class_name: Cow<'_, str> = (&class_name).into(); - - let Ok(message) = env.get_string(&message) else { - return; - }; - let message: Cow<'_, str> = (&message).into(); - - macro_rules! event { - ($lvl:expr) => { - tracing::event!( - target: "risingwave_connector_node", - $lvl, - class = class_name.as_ref(), - "{message}", - ) - }; - } - - // See `com.risingwave.tracing.TracingSlf4jImpl`. - match level { - 0 => event!(Level::ERROR), - 1 => event!(Level::WARN), - 2 => event!(Level::INFO), - 3 => event!(Level::DEBUG), - 4 => event!(Level::TRACE), - _ => unreachable!(), - } + execute_and_catch(env, move |env| { + let class_name = env.get_string(&class_name)?; + let class_name: Cow<'_, str> = (&class_name).into(); + + let message = env.get_string(&message)?; + let message: Cow<'_, str> = (&message).into(); + + macro_rules! event { + ($lvl:expr) => { + tracing::event!( + target: "risingwave_connector_node", + $lvl, + class = class_name.as_ref(), + "{message}", + ) + }; + } + + // See `com.risingwave.tracing.TracingSlf4jImpl`. + match level { + 0 => event!(Level::ERROR), + 1 => event!(Level::WARN), + 2 => event!(Level::INFO), + 3 => event!(Level::DEBUG), + 4 => event!(Level::TRACE), + _ => unreachable!(), + } + + Ok(()) + }) }