Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Risingwavelabs Risingwave TracingSlf4jImpl

From Leeroopedia
Revision as of 16:33, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Risingwavelabs_Risingwave_TracingSlf4jImpl.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Property Value
Component Connector Node - Tracing
Language Java
Lines 77
License Apache 2.0
Ported From tracing-slf4j
Repository risingwavelabs/risingwave

Overview

TracingSlf4jImpl is the core JNI bridge class that connects Java SLF4J log events to RisingWave's native Rust tracing system. It maps SLF4J log levels to integer constants understood by the Rust binding layer and provides two primary static methods: event() for emitting log events and isEnabled() for checking whether a given log level is active.

Log level enablement flags are cached as static final booleans at class load time by querying the Rust tracing system through Binding.tracingSlf4jEventEnabled(). This means the effective log level is determined once during JVM startup and remains constant for the lifetime of the process.

The actual log event emission is performed by Binding.tracingSlf4jEvent(), which is a JNI native method that forwards the thread name, logger name, level, message, and optional stack trace to the Rust tracing subscriber.

Code Reference

Source Location

java/connector-node/tracing/src/main/java/com/risingwave/tracing/TracingSlf4jImpl.java

View on GitHub

Signature

public class TracingSlf4jImpl

Constants

private static final int BINDING_ERROR = 0;
private static final int BINDING_WARN  = 1;
private static final int BINDING_INFO  = 2;
private static final int BINDING_DEBUG = 3;
private static final int BINDING_TRACE = 4;

Cached Level Enablement

private static final boolean isErrorEnabled = Binding.tracingSlf4jEventEnabled(BINDING_ERROR);
private static final boolean isWarnEnabled  = Binding.tracingSlf4jEventEnabled(BINDING_WARN);
private static final boolean isInfoEnabled  = Binding.tracingSlf4jEventEnabled(BINDING_INFO);
private static final boolean isDebugEnabled = Binding.tracingSlf4jEventEnabled(BINDING_DEBUG);
private static final boolean isTraceEnabled = Binding.tracingSlf4jEventEnabled(BINDING_TRACE);

Key Methods

// Maps an SLF4J Level to the corresponding binding integer constant
private static int levelToBinding(Level level)

// Emits a log event to the Rust tracing system via JNI
public static void event(String name, Level level, String message, String stackTrace)

// Checks whether the given log level is enabled (cached at class load time)
public static boolean isEnabled(Level level)

Imports

import com.risingwave.java.binding.Binding;
import org.slf4j.event.Level;

I/O Contract

Input

  • name (String): The logger name identifying the source of the log event.
  • level (Level): The SLF4J log level (TRACE, DEBUG, INFO, WARN, ERROR).
  • message (String): The formatted log message.
  • stackTrace (String): An optional stack trace string, or null if no exception is present.

Output

  • event(): Calls Binding.tracingSlf4jEvent(threadName, name, level, message, stackTrace), which forwards the event to the Rust tracing subscriber. The thread name is obtained from Thread.currentThread().getName().
  • isEnabled(): Returns a cached boolean indicating whether the given level is active in the Rust tracing system.

Side Effects

  • JNI calls: Each invocation of event() performs a JNI call to the Rust native library.
  • Static initialization: At class load time, five JNI calls are made to Binding.tracingSlf4jEventEnabled() to cache the level enablement flags.

Usage Examples

Direct Usage (Called by TracingSlf4jAdapter)

// Check if a level is enabled before formatting expensive messages
if (TracingSlf4jImpl.isEnabled(Level.DEBUG)) {
    TracingSlf4jImpl.event("com.example.MyClass", Level.DEBUG, "Detailed state: " + state, null);
}

// Emit an error event with stack trace
String stackTrace = ExceptionUtils.getStackTrace(exception);
TracingSlf4jImpl.event("com.example.MyClass", Level.ERROR, "Processing failed", stackTrace);

Level Mapping

SLF4J Level Binding Constant Integer Value
ERROR BINDING_ERROR 0
WARN BINDING_WARN 1
INFO BINDING_INFO 2
DEBUG BINDING_DEBUG 3
TRACE BINDING_TRACE 4

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment