From 3f6134d211c506d7cb4e0a2c75a17235c30e91fc Mon Sep 17 00:00:00 2001 From: Yury-Fridlyand Date: Tue, 5 Mar 2024 10:49:07 -0800 Subject: [PATCH] experiment Signed-off-by: Yury-Fridlyand --- .../glide/ffi/resolvers/LogLevelResolver.java | 9 +++++++++ .../test/java/glide/TestConfiguration.java | 6 ++++++ java/src/lib.rs | 20 ++++++++++++++++++- 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 java/client/src/main/java/glide/ffi/resolvers/LogLevelResolver.java diff --git a/java/client/src/main/java/glide/ffi/resolvers/LogLevelResolver.java b/java/client/src/main/java/glide/ffi/resolvers/LogLevelResolver.java new file mode 100644 index 0000000000..25be9e33b1 --- /dev/null +++ b/java/client/src/main/java/glide/ffi/resolvers/LogLevelResolver.java @@ -0,0 +1,9 @@ +package glide.ffi.resolvers; + +public class LogLevelResolver { + static { + System.loadLibrary("glide_rs"); + } + + public static native void setLogLevel(int level); +} diff --git a/java/integTest/src/test/java/glide/TestConfiguration.java b/java/integTest/src/test/java/glide/TestConfiguration.java index aa6bfd35b9..9f5e9c86ed 100644 --- a/java/integTest/src/test/java/glide/TestConfiguration.java +++ b/java/integTest/src/test/java/glide/TestConfiguration.java @@ -1,6 +1,8 @@ /** Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0 */ package glide; +import glide.ffi.resolvers.LogLevelResolver; + import java.lang.Runtime.Version; import java.util.Arrays; @@ -16,4 +18,8 @@ private static int[] getPortsFromProperty(String propName) { .mapToInt(Integer::parseInt) .toArray(); } + + static { + LogLevelResolver.setLogLevel(3); + } } diff --git a/java/src/lib.rs b/java/src/lib.rs index cb381b0ebb..2bd7c536c8 100644 --- a/java/src/lib.rs +++ b/java/src/lib.rs @@ -4,9 +4,10 @@ use glide_core::start_socket_listener; use jni::objects::{JClass, JObject, JObjectArray, JThrowable}; -use jni::sys::jlong; +use jni::sys::{jint, jlong}; use jni::JNIEnv; use log::error; +use logger_core::{init, Level}; use redis::Value; use std::sync::mpsc; @@ -153,3 +154,20 @@ fn throw_java_exception(mut env: JNIEnv, message: String) { } }; } + +#[no_mangle] +pub extern "system" fn Java_glide_ffi_resolvers_LogLevelResolver_setLogLevel<'local>( + _env: JNIEnv<'local>, + _class: JClass<'local>, + value: jint, +) { + let level: Level = match value { + 0 => Level::Error, + 1 => Level::Warn, + 2 => Level::Info, + 3 => Level::Debug, + 4 => Level::Trace, + _ => panic!(), + }; + init(Some(level), None); +}