use of org.apache.logging.log4j.core.config.ConfigurationSource in project spring-boot by spring-projects.
the class Log4J2LoggingSystem method loadConfiguration.
protected void loadConfiguration(String location, LogFile logFile) {
Assert.notNull(location, "Location must not be null");
try {
LoggerContext ctx = getLoggerContext();
URL url = ResourceUtils.getURL(location);
ConfigurationSource source = getConfigurationSource(url);
ctx.start(ConfigurationFactory.getInstance().getConfiguration(ctx, source));
} catch (Exception ex) {
throw new IllegalStateException("Could not initialize Log4J2 logging from " + location, ex);
}
}
use of org.apache.logging.log4j.core.config.ConfigurationSource in project logging-log4j2 by apache.
the class CompositeConfiguration method reconfigure.
@Override
public Configuration reconfigure() {
LOGGER.debug("Reconfiguring composite configuration");
final List<AbstractConfiguration> configs = new ArrayList<>();
final ConfigurationFactory factory = ConfigurationFactory.getInstance();
for (final AbstractConfiguration config : configurations) {
final ConfigurationSource source = config.getConfigurationSource();
final URI sourceURI = source.getURI();
Configuration currentConfig;
if (sourceURI != null) {
LOGGER.warn("Unable to determine URI for configuration {}, changes to it will be ignored", config.getName());
currentConfig = factory.getConfiguration(getLoggerContext(), config.getName(), sourceURI);
if (currentConfig == null) {
LOGGER.warn("Unable to reload configuration {}, changes to it will be ignored", config.getName());
currentConfig = config;
}
} else {
currentConfig = config;
}
configs.add((AbstractConfiguration) currentConfig);
}
return new CompositeConfiguration(configs);
}
use of org.apache.logging.log4j.core.config.ConfigurationSource in project logging-log4j2 by apache.
the class XmlConfiguration method reconfigure.
@Override
public Configuration reconfigure() {
try {
final ConfigurationSource source = getConfigurationSource().resetInputStream();
if (source == null) {
return null;
}
final XmlConfiguration config = new XmlConfiguration(getLoggerContext(), source);
return config.rootElement == null ? null : config;
} catch (final IOException ex) {
LOGGER.error("Cannot locate file {}", getConfigurationSource(), ex);
}
return null;
}
use of org.apache.logging.log4j.core.config.ConfigurationSource in project logging-log4j2 by apache.
the class PropertiesConfiguration method reconfigure.
@Override
public Configuration reconfigure() {
try {
final ConfigurationSource source = getConfigurationSource().resetInputStream();
if (source == null) {
return null;
}
final PropertiesConfigurationFactory factory = new PropertiesConfigurationFactory();
final PropertiesConfiguration config = factory.getConfiguration(getLoggerContext(), source);
return config == null || config.getState() != State.INITIALIZING ? null : config;
} catch (final IOException ex) {
LOGGER.error("Cannot locate file {}: {}", getConfigurationSource(), ex);
}
return null;
}
use of org.apache.logging.log4j.core.config.ConfigurationSource in project logging-log4j2 by apache.
the class Log4jLookup method lookup.
@Override
public String lookup(final LogEvent event, final String key) {
if (configuration != null) {
final ConfigurationSource configSrc = configuration.getConfigurationSource();
final File file = configSrc.getFile();
if (file != null) {
switch(key) {
case KEY_CONFIG_LOCATION:
return file.getAbsolutePath();
case KEY_CONFIG_PARENT_LOCATION:
return file.getParentFile().getAbsolutePath();
default:
return null;
}
}
final URL url = configSrc.getURL();
if (url != null) {
try {
switch(key) {
case KEY_CONFIG_LOCATION:
return asPath(url.toURI());
case KEY_CONFIG_PARENT_LOCATION:
return asPath(getParent(url.toURI()));
default:
return null;
}
} catch (final URISyntaxException use) {
LOGGER.error(use);
return null;
}
}
}
return null;
}
Aggregations