[Fix] Fixed LoggingLoader.reloadLogging()
This commit is contained in:
parent
5064249e72
commit
c17b23b72f
|
@ -8,7 +8,6 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.MalformedURLException;
|
||||
|
||||
public class LoggingLoader {
|
||||
|
||||
|
@ -26,22 +25,25 @@ public class LoggingLoader {
|
|||
"Not changing logback configuration as " + logConfigFile.getAbsolutePath() + " does not exist.");
|
||||
} else {
|
||||
if (!(LoggerFactory.getILoggerFactory() instanceof LoggerContext loggerContext)) {
|
||||
logger.error(logConfigFile.getAbsolutePath() +
|
||||
" exists, but LoggerFactory is not instance of ch.qos.logback.classic.LoggerContext. Ignoring.");
|
||||
logger.error(logConfigFile.getAbsolutePath()
|
||||
+ " exists, but LoggerFactory is not instance of ch.qos.logback.classic.LoggerContext. Ignoring.");
|
||||
} else {
|
||||
logger.info(logConfigFile.getAbsolutePath() + " file exists. Reloading logging configuration from " +
|
||||
logConfigFile);
|
||||
logger.info(logConfigFile.getAbsolutePath()
|
||||
+ " file exists. Reloading logging configuration from "
|
||||
+ logConfigFile);
|
||||
try {
|
||||
loggerContext.reset();
|
||||
new DefaultJoranConfigurator().configureByResource(logConfigFile.toURI().toURL());
|
||||
DefaultJoranConfigurator configurator = new DefaultJoranConfigurator();
|
||||
configurator.setContext(loggerContext);
|
||||
configurator.configureByResource(logConfigFile.toURI().toURL());
|
||||
logger.info("Reloaded logger configuration from " + logConfigFile.getAbsolutePath());
|
||||
lastConfigFile = logConfigFile;
|
||||
} catch (MalformedURLException | JoranException e) {
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
new ContextInitializer(loggerContext).autoConfig();
|
||||
} catch (JoranException e1) {
|
||||
logger.error("Failed to reload original config after failure to load new config from " +
|
||||
logConfigFile.getAbsolutePath(), e);
|
||||
logger.error("Failed to reload original config after failure to load new config from "
|
||||
+ logConfigFile.getAbsolutePath(), e);
|
||||
}
|
||||
logger.error("Failed to reload logback configuration from file " + logConfigFile, e);
|
||||
}
|
||||
|
@ -56,10 +58,12 @@ public class LoggingLoader {
|
|||
reloadLogging(lastConfigFile.getParentFile());
|
||||
} 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!");
|
||||
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...");
|
||||
|
|
Loading…
Reference in New Issue