[New] Updated to slf4j 2.x and logback 1.4.x
Updated LoggingLoader to reset configuration
This commit is contained in:
parent
3d74f5eaab
commit
2f05e768aa
|
@ -15,6 +15,8 @@ public class LoggingLoader {
|
|||
|
||||
private static final String LOGBACK_XML = "logback.xml";
|
||||
|
||||
private static File lastConfigFile;
|
||||
|
||||
public static void reloadLogging(File configPathF) {
|
||||
|
||||
File logConfigFile = new File(configPathF, LOGBACK_XML);
|
||||
|
@ -29,9 +31,10 @@ public class LoggingLoader {
|
|||
logger.info(logConfigFile.getAbsolutePath() + " file exists. Reloading logging configuration from "
|
||||
+ logConfigFile);
|
||||
try {
|
||||
loggerContext.reset();
|
||||
//loggerContext.reset();
|
||||
new ContextInitializer(loggerContext).configureByResource(logConfigFile.toURI().toURL());
|
||||
logger.info("Reloaded logger configuration from " + logConfigFile.getAbsolutePath());
|
||||
lastConfigFile = logConfigFile;
|
||||
} catch (MalformedURLException | JoranException e) {
|
||||
try {
|
||||
new ContextInitializer(loggerContext).autoConfig();
|
||||
|
@ -44,4 +47,31 @@ public class LoggingLoader {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void reloadLoggingConfiguration() {
|
||||
if (lastConfigFile != null) {
|
||||
logger.info("Reloading configuration from last config file " + lastConfigFile.getAbsolutePath());
|
||||
System.out.println("Reloading configuration from last config file " + lastConfigFile.getAbsolutePath());
|
||||
reloadLogging(lastConfigFile);
|
||||
} else {
|
||||
if (!(LoggerFactory.getILoggerFactory() instanceof LoggerContext loggerContext)) {
|
||||
logger.error("LoggerFactory is not instance of " + LoggerContext.class.getName()
|
||||
+ ". Ignoring request to reload configuration!");
|
||||
System.out.println("LoggerFactory is not instance of " + LoggerContext.class.getName()
|
||||
+ ". Ignoring request to reload configuration!");
|
||||
} else {
|
||||
logger.info(
|
||||
"Resetting logging configuration using auto config as no previous config fila available...");
|
||||
System.out.println(
|
||||
"Resetting logging configuration using auto config as no previous config fila available...");
|
||||
try {
|
||||
new ContextInitializer(loggerContext).autoConfig();
|
||||
} catch (JoranException e) {
|
||||
logger.error("Failed to do logging auto configuration", e);
|
||||
System.out.println("Failed to do logging auto configuration");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
4
pom.xml
4
pom.xml
|
@ -80,8 +80,8 @@
|
|||
<maven.compiler.target>${jdk.version}</maven.compiler.target>
|
||||
|
||||
<!-- compile time dependencies -->
|
||||
<slf4j.version>1.7.30</slf4j.version>
|
||||
<logback.version>1.2.9</logback.version>
|
||||
<slf4j.version>2.0.5</slf4j.version>
|
||||
<logback.version>1.4.5</logback.version>
|
||||
<jersey.version>2.34</jersey.version>
|
||||
<gson.version>2.8.9</gson.version>
|
||||
<hikaricp.version>5.0.0</hikaricp.version>
|
||||
|
|
Loading…
Reference in New Issue