Skip to content

Improve logging: SLF4J bridge, less startup noise, fix shutdown log loss #6583

@halibobo1205

Description

@halibobo1205

Background

The current java-tron logging system has three concrete problems affecting observability, startup clarity, and graceful shutdown:

  • gRPC logs bypass Logback and go directly to stderr. grpc-java uses java.util.logging (JUL) internally. While the project already includes jcl-over-slf4j, the JUL→SLF4J bridge is absent. As a result, gRPC diagnostic messages — connection resets, TLS handshake failures, etc. — never reach tron.log, forcing operators to monitor both stderr and log files simultaneously during RPC troubleshooting (see grpc-java#1577).
  • DB stats logging generates excessive INFO noise at startup. DbStat.statProperty() logs at INFO level, flooding startup output and burying critical initialization messages.
  • Shutdown logs are incomplete on abnormal exits. After receiving SIGTERM, TronLogShutdownHook waits up to 60 seconds before closing. If the node hangs during this window, critical shutdown-phase logs may never be flushed.

Core Changes

  1. JUL→SLF4J bridge: Add jul-to-slf4j as a dependency and call SLF4JBridgeHandler.install() at the earliest possible point during node startup, after resetting the default JUL handlers. This routes all gRPC JUL output into SLF4J/Logback for centralized collection.

java

// Remove default JUL handlers to prevent duplicate output
java.util.logging.LogManager.getLogManager().reset();
SLF4JBridgeHandler.install();

groovy

// build.gradle
implementation 'org.slf4j:jul-to-slf4j:1.7.36'
  1. DB stats log level downgrade: Change log.info(...) calls in DbStat.statProperty() and similar high-frequency periodic stat methods to log.debug(...), reducing startup noise without losing diagnostic value.
  2. Shutdown log completeness: Introduce a volatile boolean shuttingDown flag in TronLogShutdownHook, shorten unnecessary wait intervals, and ensure critical log buffers are flushed as a first-priority step in the JVM shutdown hook.

Configuration Changes

  • Add an explicit logger level entry for io.grpc in logback.xml so operators can tune gRPC log verbosity independently.
  • DB stats loggers default to DEBUG; operators can promote them on demand.

No API / Protocol Changes

This change has no impact on external APIs or the network protocol.

Testing Strategy

  1. Verify that gRPC diagnostic logs (connection resets, TLS failures, etc.) appear in tron.log and are no longer emitted to stderr.
  2. Compare INFO-level log entry counts during node startup before and after — confirm a significant reduction in DB stats noise.
  3. Simulate an abnormal shutdown (send SIGTERM, then stall the process) and verify that critical shutdown-phase entries are complete and timely.

Performance Considerations

  • SLF4JBridgeHandler introduces marginal overhead for JUL log forwarding, but gRPC diagnostic logs are infrequent during normal operation — the impact is negligible.
  • Downgrading DB stats logs reduces log I/O volume with no runtime performance cost.

Scope of Impact

  • Other: logging initialization, DB module stats log level, node shutdown lifecycle

Breaking Changes: None  

Backward Compatibility: None

Alternatives Considered None

References

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions