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 7 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 · |
**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>
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 · |
Signed-off-by: imalasong <imalasong@qq.com>
|
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. |
User description
CodeAnt-AI Description
Route runtime logs into the main app logs and keep shutdown logs from being lost
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.