Replace printStackTrace with proper logging in LogbackUtils
Author: lxcxjxhxCreated Jul 30, 2026Updated Jul 30, 2026
Issue: Replace printStackTrace with proper logging in LogbackUtils
Problem
The LogbackUtils.destroy() method in sandbox-core uses cause.printStackTrace() to handle exceptions, which:
- Bypasses the logging framework (SLF4J/Logback)
- Outputs directly to System.err instead of configured log appenders
- Is inconsistent with the
init()method in the same class, which properly useslogger.warn()
Location
File: sandbox-core/src/main/java/com/alibaba/jvm/sandbox/core/util/LogbackUtils.java
Method: destroy()
Line: 56
Current Behavior
public static void destroy() {
try {
((LoggerContext) LoggerFactory.getILoggerFactory()).stop();
} catch (Throwable cause) {
cause.printStackTrace(); // <-- Problem
}
}Expected Behavior
Should use proper logging like the init() method does:
public static void destroy() {
final Logger logger = LoggerFactory.getLogger(LogbackUtils.class);
try {
((LoggerContext) LoggerFactory.getILoggerFactory()).stop();
} catch (Throwable cause) {
logger.warn("destroy logback failed", cause); // <-- Proper logging
}
}Impact
- Improves consistency within the same class
- Ensures exceptions are properly logged through the configured logging framework
- Makes debugging easier in production environments
Solution
Replace printStackTrace() with logger.warn() using the existing SLF4J logger.
Source: alibaba/jvm-sandbox