mirror of
https://github.com/gmbrax/MediaManager-core.git
synced 2026-11-09 22:10:17 +00:00
Improve logging, shutdown behavior, and build configuration:
- Enabled `immediateFlush` for log appenders and disabled `shutdownHook` in Log4j2 configuration. - Enhanced shutdown hook with graceful Log4j2 termination and extended delay for log flushing. - Improved database connection closure logging in `DatabaseManager`. - Integrated Maven Shade Plugin to create executable JARs with all dependencies.
This commit is contained in:
parent
b0c45bf657
commit
b7ff9d1e16
@@ -32,19 +32,28 @@ public class MediaManagerApplication {
|
||||
|
||||
// Keep application running
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
||||
|
||||
logger.info("Shutting down MediaManager Core...");
|
||||
|
||||
|
||||
if (databaseManager != null) {
|
||||
databaseManager.close();
|
||||
}
|
||||
|
||||
// TODO: Cleanup resources
|
||||
|
||||
logger.info("MediaManager Core shutdown successfully");
|
||||
logger.info("Goodbye!");
|
||||
|
||||
|
||||
// Give Log4j2 time to write all pending messages before shutting down
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
|
||||
// Now shutdown Log4j2
|
||||
org.apache.logging.log4j.LogManager.shutdown();
|
||||
}));
|
||||
logger.info("Application is running");
|
||||
logger.info("Press Ctrl+C to exit");
|
||||
|
||||
@@ -88,11 +88,14 @@ public class DatabaseManager {
|
||||
public void close() {
|
||||
if (connection != null) {
|
||||
try {
|
||||
logger.info("Closing database connection...");
|
||||
connection.close();
|
||||
logger.info("Database connection closed successfully");
|
||||
} catch (SQLException e) {
|
||||
logger.error("Failed to close database connection", e);
|
||||
logger.error("Error closing database connection: {}", e.getMessage());
|
||||
}
|
||||
} else {
|
||||
logger.debug("No database connection to close");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user