Skip to content

Commit

Permalink
experiment
Browse files Browse the repository at this point in the history
Signed-off-by: Yury-Fridlyand <[email protected]>
  • Loading branch information
Yury-Fridlyand committed Mar 5, 2024
1 parent 07b6a43 commit 3f6134d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package glide.ffi.resolvers;

public class LogLevelResolver {
static {
System.loadLibrary("glide_rs");
}

public static native void setLogLevel(int level);
}
6 changes: 6 additions & 0 deletions java/integTest/src/test/java/glide/TestConfiguration.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -16,4 +18,8 @@ private static int[] getPortsFromProperty(String propName) {
.mapToInt(Integer::parseInt)
.toArray();
}

static {
LogLevelResolver.setLogLevel(3);
}
}
20 changes: 19 additions & 1 deletion java/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}

0 comments on commit 3f6134d

Please sign in to comment.