feat(log): bridge JUL to SLF4J and improve shutdown log reliability#122
feat(log): bridge JUL to SLF4J and improve shutdown log reliability#122halibobo1205 wants to merge 3 commits intodevelopfrom
Conversation
|
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 · |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
framework/src/main/java/org/tron/core/config/TronLogShutdownHook.java
Outdated
Show resolved
Hide resolved
|
CodeAnt AI finished reviewing your PR. |
|
@CodeAnt-AI: review |
|
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 · |
Sequence DiagramThis 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
Generated by CodeAnt AI |
framework/src/main/java/org/tron/core/config/TronLogShutdownHook.java
Outdated
Show resolved
Hide resolved
common/src/main/java/org/tron/common/parameter/CommonParameter.java
Outdated
Show resolved
Hide resolved
common/src/main/java/org/tron/common/parameter/CommonParameter.java
Outdated
Show resolved
Hide resolved
|
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 · |
|
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 · |
|
CodeAnt AI Incremental review completed. |
|
@CodeAnt-AI: review |
|
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 · |
Sequence DiagramThis 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
Generated by CodeAnt AI |
|
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 · |
ee010fd to
5374d8b
Compare
|
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 · |
|
@CodeAnt-AI: review |
|
CodeAnt AI Incremental review completed. |
|
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 · |
Sequence DiagramThis 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
Generated by CodeAnt AI |
| <!-- Allow up to 5 s to drain the queue on shutdown before giving up --> | ||
| <maxFlushTime>5000</maxFlushTime> |
There was a problem hiding this comment.
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.| <!-- 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 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 · |
|
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 · |
|
CodeAnt AI Incremental review completed. |
|
@codex: review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 085df904b8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
**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>
085df90 to
4dd6968
Compare
|
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 · |
|
CodeAnt AI Incremental review completed. |
- Add LevelChangePropagator so Logback level changes are propagated
back to JUL, eliminating the 60x overhead for disabled log statements
when using the jul-to-slf4j bridge; without this, Level.ALL set in
CommonParameter would remain in effect permanently
Note: users with a custom logback.xml must also add LevelChangePropagator
to get the same performance benefit:
<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
<resetJUL>true</resetJUL>
</contextListener>
Without it, the JUL root logger remains at Level.ALL (set in
CommonParameter for bridge compatibility), meaning every JUL LogRecord
is constructed and handed to the bridge regardless of the effective
Logback level — incurring the full 60x overhead on disabled statements.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
@codex: review |
|
@CodeAnt-AI: review |
|
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 · |
Sequence DiagramThis PR routes Java util logging (including gRPC diagnostics) into Logback via an SLF4J bridge and improves shutdown so queued logs have more time to flush reliably. sequenceDiagram
participant Node
participant JULLogger
participant Bridge
participant Logback
participant AsyncAppender
participant ShutdownHook
Node->>Bridge: Install JUL to SLF4J bridge and set JUL root level
JULLogger->>Bridge: Emit gRPC warning log
Bridge->>Logback: Forward log event
Logback->>JULLogger: Propagate effective log level to JUL
Logback->>AsyncAppender: Enqueue log for async write
Node->>ShutdownHook: Trigger application shutdown
ShutdownHook->>ShutdownHook: Wait for graceful shutdown up to max wait
ShutdownHook->>Logback: Stop context and flush logs
AsyncAppender->>Logback: Drain queue within max flush time
Generated by CodeAnt AI |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 13d88692a1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (!SLF4JBridgeHandler.isInstalled()) { | ||
| SLF4JBridgeHandler.install(); | ||
| } | ||
| Logger.getLogger("io.grpc").setLevel(Level.ALL); |
There was a problem hiding this comment.
Apply gRPC JUL level after Logback reset
Logger.getLogger("io.grpc").setLevel(Level.ALL) runs in CommonParameter static init, but during normal startup Args.setParam(...) triggers this before logging is configured and LogService.load(...) then reloads logback.xml with LevelChangePropagator + resetJUL=true. In logback 1.2.x, that reset clears explicit JUL logger levels, so this io.grpc override is lost and the extra gRPC diagnostics this change aims to capture remain filtered by inherited JUL levels. Move this level assignment to run after logback configuration (or set the logger level via logback config) so it actually takes effect.
Useful? React with 👍 / 👎.
|
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 · |
DEBUG root level floods test output with RocksDB startup, gRPC handshake and Spring container noise, making it hard to spot real failures. WARN keeps the signal-to-noise ratio high; Test/Manager loggers stay at DEBUG since test assertions may rely on those messages. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
User description
CodeAnt-AI Description
Route runtime and shutdown logs into the main application logs
What Changed
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:
This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.
Example
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:
This helps CodeAnt AI learn and adapt to your team's coding style and standards.
Example
Retrigger review
Ask CodeAnt AI to review the PR again, by typing:
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.