Merge pull request #3 from gmbrax/fix/Fix-exir-log-messages
Improve logging, shutdown behavior, and build configuration:
This commit is contained in:
commit
81e38ce9ae
22
pom.xml
22
pom.xml
|
|
@ -96,6 +96,28 @@
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
<version>3.2.5</version>
|
<version>3.2.5</version>
|
||||||
</plugin>
|
</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>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,19 +32,28 @@ public class MediaManagerApplication {
|
||||||
|
|
||||||
// Keep application running
|
// Keep application running
|
||||||
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
||||||
|
|
||||||
logger.info("Shutting down MediaManager Core...");
|
logger.info("Shutting down MediaManager Core...");
|
||||||
|
|
||||||
|
|
||||||
if (databaseManager != null) {
|
if (databaseManager != null) {
|
||||||
databaseManager.close();
|
databaseManager.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Cleanup resources
|
|
||||||
|
|
||||||
logger.info("MediaManager Core shutdown successfully");
|
logger.info("MediaManager Core shutdown successfully");
|
||||||
|
logger.info("Goodbye!");
|
||||||
|
|
||||||
|
|
||||||
|
// Give Log4j2 time to write all pending messages before shutting down
|
||||||
try {
|
try {
|
||||||
Thread.sleep(500);
|
Thread.sleep(1000);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Now shutdown Log4j2
|
||||||
|
org.apache.logging.log4j.LogManager.shutdown();
|
||||||
}));
|
}));
|
||||||
logger.info("Application is running");
|
logger.info("Application is running");
|
||||||
logger.info("Press Ctrl+C to exit");
|
logger.info("Press Ctrl+C to exit");
|
||||||
|
|
|
||||||
|
|
@ -88,11 +88,14 @@ public class DatabaseManager {
|
||||||
public void close() {
|
public void close() {
|
||||||
if (connection != null) {
|
if (connection != null) {
|
||||||
try {
|
try {
|
||||||
|
logger.info("Closing database connection...");
|
||||||
connection.close();
|
connection.close();
|
||||||
logger.info("Database connection closed successfully");
|
logger.info("Database connection closed successfully");
|
||||||
} catch (SQLException e) {
|
} 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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,13 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<Configuration status="WARN">
|
<Configuration status="WARN" shutdownHook="disable">
|
||||||
<Appenders>
|
<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"/>
|
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} [%t] %-5level %logger{36} - %msg%n"/>
|
||||||
</Console>
|
</Console>
|
||||||
|
|
||||||
<RollingFile name="FileAppender" fileName="logs/mediamanager.log"
|
<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"/>
|
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} [%t] %-5level %logger{36} - %msg%n"/>
|
||||||
<Policies>
|
<Policies>
|
||||||
<TimeBasedTriggeringPolicy interval="1"/>
|
<TimeBasedTriggeringPolicy interval="1"/>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue