Merge pull request #3 from gmbrax/fix/Fix-exir-log-messages

Improve logging, shutdown behavior, and build configuration:
This commit is contained in:
Gustavo Henrique Miranda 2025-11-13 17:18:47 -03:00 committed by GitHub
commit 81e38ce9ae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 41 additions and 6 deletions

22
pom.xml
View File

@ -96,6 +96,28 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
</plugin>
<!-- Maven Shade Plugin - Creates executable JAR with all dependencies -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.mediamanager.MediaManagerApplication</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

View File

@ -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");

View File

@ -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");
}
}
}

View File

@ -1,12 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Configuration status="WARN" shutdownHook="disable">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<Console name="Console" target="SYSTEM_OUT" immediateFlush="true">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
<RollingFile name="FileAppender" fileName="logs/mediamanager.log"
filePattern="logs/mediamanager-%d{yyyy-MM-dd}-%i.log">
filePattern="logs/mediamanager-%d{yyyy-MM-dd}-%i.log"
immediateFlush="true">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} [%t] %-5level %logger{36} - %msg%n"/>
<Policies>
<TimeBasedTriggeringPolicy interval="1"/>