Skip to content

feat(log): bridge JUL to SLF4J and improve shutdown log reliability#122

Open
halibobo1205 wants to merge 7 commits intodevelopfrom
feat/log_grpc
Open

feat(log): bridge JUL to SLF4J and improve shutdown log reliability#122
halibobo1205 wants to merge 7 commits intodevelopfrom
feat/log_grpc

Conversation

@halibobo1205
Copy link
Copy Markdown
Owner

@halibobo1205 halibobo1205 commented Apr 4, 2026

User description

  • Add jul-to-slf4j:1.7.36 dependency; upgrade slf4j-api and jcl-over-slf4j from 1.7.25 to 1.7.36 so all three bridge modules are version-aligned
  • Install SLF4JBridgeHandler in CommonParameter static initializer so gRPC-java diagnostic logs (connection resets, TLS failures, etc.) are routed into Logback instead of going to stderr only
  • Reduce DbStat.statProperty() from INFO to DEBUG to suppress per-level SST stats noise that floods startup output
  • Extend TronLogShutdownHook max wait to 120 s (up from 60 s) to cover the ExecutorServiceManager 60 s force-shutdown window; update comment to reflect actual usage (direct kill -15, not systemd)
  • Add maxFlushTime=5000 to AsyncAppender so the queue is given up to 5 s to drain when logback context stops, preventing log loss on hung shutdown
  • Update verification-metadata.xml with SHA-256 checksums for new artifacts

CodeAnt-AI Description

Route runtime logs into the main app logs and keep shutdown logs from being lost

What Changed

  • Java runtime and gRPC warnings now show up in the app logs instead of only on standard error.
  • Startup database stats are no longer printed at info level, which cuts noisy output.
  • Shutdown now waits longer and gives log messages more time to flush before the app exits.
  • Genesis block timestamps now reject negative values with a clearer error.
  • Test logs hide very verbose RocksDB and metrics output.
  • Pull request checks now include coverage gating, and reviewer assignment is added automatically from the PR scope.
  • Contributor docs were updated to use the current issue and PR submission flow.

Impact

✅ Fewer missed gRPC error logs
✅ Cleaner startup output
✅ Fewer lost shutdown logs

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

@codeant-ai
Copy link
Copy Markdown

codeant-ai bot commented Apr 4, 2026

CodeAnt AI is reviewing your PR.


Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@codeant-ai codeant-ai bot added the size:M This PR changes 30-99 lines, ignoring generated files label Apr 4, 2026
@codeant-ai
Copy link
Copy Markdown

codeant-ai bot commented Apr 4, 2026

CodeAnt AI finished reviewing your PR.

@halibobo1205
Copy link
Copy Markdown
Owner Author

@CodeAnt-AI: review

@codeant-ai
Copy link
Copy Markdown

codeant-ai bot commented Apr 5, 2026

CodeAnt AI is running the review.


Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@codeant-ai codeant-ai bot added size:M This PR changes 30-99 lines, ignoring generated files and removed size:M This PR changes 30-99 lines, ignoring generated files labels Apr 5, 2026
@codeant-ai
Copy link
Copy Markdown

codeant-ai bot commented Apr 5, 2026

Sequence Diagram

This PR routes Java runtime and gRPC JUL logs into the standard SLF4J/Logback pipeline and extends the log shutdown hook to wait longer and flush the async queue, reducing lost logs during shutdown.

sequenceDiagram
    participant Node
    participant JulLogger
    participant Slf4jBridge
    participant LoggingSystem
    participant LogFile
    participant ShutdownHook

    Node->>JulLogger: Emit runtime diagnostic log
    JulLogger->>Slf4jBridge: Forward JUL log record
    Slf4jBridge->>LoggingSystem: Route as SLF4J event
    LoggingSystem->>LogFile: Append to application log

    Node->>ShutdownHook: JVM shutdown starts
    ShutdownHook->>Node: Wait for graceful shutdown up to 120 s
    ShutdownHook->>LoggingSystem: Stop logging and flush queue up to 5 s
    LoggingSystem->>LogFile: Persist remaining log events
Loading

Generated by CodeAnt AI

@codeant-ai
Copy link
Copy Markdown

codeant-ai bot commented Apr 5, 2026

CodeAnt AI finished running the review.


Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@codeant-ai
Copy link
Copy Markdown

codeant-ai bot commented Apr 7, 2026

CodeAnt AI is running Incremental review


Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@codeant-ai codeant-ai bot added size:M This PR changes 30-99 lines, ignoring generated files and removed size:M This PR changes 30-99 lines, ignoring generated files labels Apr 7, 2026
@codeant-ai
Copy link
Copy Markdown

codeant-ai bot commented Apr 7, 2026

CodeAnt AI Incremental review completed.

@halibobo1205
Copy link
Copy Markdown
Owner Author

@CodeAnt-AI: review

@codeant-ai
Copy link
Copy Markdown

codeant-ai bot commented Apr 7, 2026

CodeAnt AI is running the review.


Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@codeant-ai codeant-ai bot added size:M This PR changes 30-99 lines, ignoring generated files and removed size:M This PR changes 30-99 lines, ignoring generated files labels Apr 7, 2026
@codeant-ai
Copy link
Copy Markdown

codeant-ai bot commented Apr 7, 2026

Sequence Diagram

This PR routes gRPC Java util logging into the existing SLF4J Logback pipeline and extends the shutdown hook to wait longer and flush the async log queue, reducing lost logs during runtime and shutdown.

sequenceDiagram
    participant Node
    participant CommonParameter
    participant gRPC
    participant LoggingBridge
    participant Logback
    participant LogFile
    participant ShutdownHook

    Node->>CommonParameter: Load configuration (static initializer)
    CommonParameter->>LoggingBridge: Install JUL to SLF4J and set gRPC log level
    gRPC->>LoggingBridge: Emit diagnostic log
    LoggingBridge->>Logback: Forward log to async appender
    Logback->>LogFile: Append application log entry

    Node->>ShutdownHook: Trigger TronLogShutdownHook on shutdown
    ShutdownHook->>ShutdownHook: Wait up to max time for graceful shutdown
    ShutdownHook->>Logback: Request async queue flush with timeout
    Logback->>LogFile: Persist remaining log entries before stop
Loading

Generated by CodeAnt AI

@codeant-ai
Copy link
Copy Markdown

codeant-ai bot commented Apr 7, 2026

CodeAnt AI finished running the review.


Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

**Route runtime diagnostics into the main logs and reduce log loss during shutdown**

### What Changed
- gRPC and other Java runtime warnings now appear in the application log instead of going only to standard error.
- Database size stats are no longer printed at info level during startup, which reduces log noise.
- Shutdown now waits longer before stopping the log system, giving pending messages more time to flush.
- Async appender now allows up to 5 seconds to drain its queue on shutdown.
- Interrupted shutdowns now show a clearer log message.
- Test log config suppresses verbose ROCKSDB and metrics output (WARN level).
- Logging dependencies were updated to keep the log routing setup aligned.

### Impact
`✅ Fewer missed gRPC error logs`
`✅ Cleaner startup output`
`✅ Fewer lost shutdown logs`

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: codeant-ai[bot] <151821869+codeant-ai[bot]@users.noreply.github.com>
@codeant-ai
Copy link
Copy Markdown

codeant-ai bot commented Apr 8, 2026

CodeAnt AI is running Incremental review


Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@codeant-ai codeant-ai bot added size:M This PR changes 30-99 lines, ignoring generated files and removed size:M This PR changes 30-99 lines, ignoring generated files labels Apr 8, 2026
@halibobo1205
Copy link
Copy Markdown
Owner Author

@CodeAnt-AI: review

@codeant-ai
Copy link
Copy Markdown

codeant-ai bot commented Apr 8, 2026

CodeAnt AI Incremental review completed.

@codeant-ai
Copy link
Copy Markdown

codeant-ai bot commented Apr 8, 2026

CodeAnt AI is running the review.


Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@codeant-ai codeant-ai bot added size:M This PR changes 30-99 lines, ignoring generated files and removed size:M This PR changes 30-99 lines, ignoring generated files labels Apr 8, 2026
@codeant-ai
Copy link
Copy Markdown

codeant-ai bot commented Apr 8, 2026

Sequence Diagram

This PR routes Java util logging (including gRPC diagnostics) into the main SLF4J/Logback pipeline and extends the shutdown hook and async appender flush behavior so more log messages are reliably written before the node exits.

sequenceDiagram
    participant Runtime as gRPC and Java runtime
    participant JUL as Java util logging
    participant Bridge as SLF4J JUL bridge
    participant Logback as Logback logger
    participant Async as Async appender
    participant LogFile as Application log file
    participant Hook as TronLogShutdownHook
    participant JVM

    Runtime->>JUL: Emit warning or error
    JUL->>Bridge: Forward log record
    Bridge->>Logback: Convert to SLF4J event
    Logback->>Async: Enqueue log message
    Async->>LogFile: Append log entry

    JVM->>Hook: Invoke on shutdown
    Hook->>Hook: Wait for application shutdown (up to max wait)
    Hook->>Logback: Stop context and trigger flush
    Logback->>Async: Flush queue (up to max flush time)
    Async->>LogFile: Write remaining log messages
Loading

Generated by CodeAnt AI

Comment on lines +64 to +65
<!-- Allow up to 5 s to drain the queue on shutdown before giving up -->
<maxFlushTime>5000</maxFlushTime>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: The async appender is configured to abandon flushing after only 5 seconds, which can still drop queued shutdown logs under slow I/O or burst logging even though shutdown now waits much longer. Increase the flush window to align with the shutdown wait budget so buffered events are not prematurely discarded. [logic error]

Severity Level: Major ⚠️
- ❌ Some shutdown log events lost from async root logger.
- ⚠️ Post-mortem analysis lacks final error messages on exit.
- ⚠️ FullNode and API service logs incomplete around termination.
Suggested change
<!-- Allow up to 5 s to drain the queue on shutdown before giving up -->
<maxFlushTime>5000</maxFlushTime>
<!-- Allow up to 120 s to drain the queue on shutdown before giving up -->
<maxFlushTime>120000</maxFlushTime>
Steps of Reproduction ✅
1. Start any java-tron node (e.g., FullNode) so Logback loads
`framework/src/main/resources/logback.xml`, which registers `TronLogShutdownHook` via
`<shutdownHook class="org.tron.core.config.TronLogShutdownHook"/>` at lines 5–6 and routes
root logging through the async appender defined at lines 56–66.

2. Drive the node under load so components like the HTTP API
(`framework/src/main/java/org/tron/core/services/http/FullNodeHttpApiService.java:18–23`,
annotated with `@Slf4j(topic = "API")`) emit many INFO/DEBUG logs, filling the async
appender queue (`queueSize=100` at `logback.xml:62`).

3. Initiate process shutdown with SIGTERM/CTRL-C so Logback's shutdown hook runs
`TronLogShutdownHook.run()`
(`framework/src/main/java/org/tron/core/config/TronLogShutdownHook.java:34–49`), which
waits up to `MAX_WAIT_MS = 3 * 60 * 1000` (lines 18–23) for a graceful shutdown and then
calls `super.stop()` to stop the Logback context.

4. At context stop, the async appender (`logback.xml:56–65`) flushes its queue but is
limited by `<maxFlushTime>5000</maxFlushTime>` (5 s); under slow I/O or a large queued
burst, events still in the queue after 5 s are dropped, so the last seconds of logs before
exit are missing from `./logs/tron.log` even though the shutdown hook allowed up to 180 s
for shutdown.
Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** framework/src/main/resources/logback.xml
**Line:** 64:65
**Comment:**
	*Logic Error: The async appender is configured to abandon flushing after only 5 seconds, which can still drop queued shutdown logs under slow I/O or burst logging even though shutdown now waits much longer. Increase the flush window to align with the shutdown wait budget so buffered events are not prematurely discarded.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
👍 | 👎

@codeant-ai
Copy link
Copy Markdown

codeant-ai bot commented Apr 8, 2026

CodeAnt AI finished running the review.


Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@codeant-ai
Copy link
Copy Markdown

codeant-ai bot commented Apr 9, 2026

CodeAnt AI is running Incremental review


Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@codeant-ai codeant-ai bot added size:L This PR changes 100-499 lines, ignoring generated files and removed size:M This PR changes 30-99 lines, ignoring generated files labels Apr 9, 2026
@codeant-ai
Copy link
Copy Markdown

codeant-ai bot commented Apr 9, 2026

CodeAnt AI Incremental review completed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants