use of org.apache.logging.log4j.core.config.xml.XmlConfiguration in project logging-log4j2 by apache.
the class AdvertiserTest method setupClass.
@BeforeAll
public static void setupClass() {
final File file = new File(STATUS_LOG);
file.delete();
System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
final LoggerContext ctx = LoggerContext.getContext();
final Configuration config = ctx.getConfiguration();
if (config instanceof XmlConfiguration) {
final String name = config.getName();
if (name == null || !name.equals("XMLConfigTest")) {
ctx.reconfigure();
}
} else {
ctx.reconfigure();
}
}
use of org.apache.logging.log4j.core.config.xml.XmlConfiguration in project logging-log4j2 by apache.
the class LateConfigTest method testReconfiguration.
@Test
public void testReconfiguration() throws Exception {
final Configuration cfg = context.getConfiguration();
assertNotNull(cfg, "No configuration");
assertTrue(cfg instanceof DefaultConfiguration, "Not set to default configuration");
final File file = new File(CONFIG);
final LoggerContext loggerContext = LoggerContext.getContext(null, false, file.toURI());
assertNotNull(loggerContext, "No Logger Context");
final Configuration newConfig = loggerContext.getConfiguration();
assertNotSame(cfg, newConfig, "Configuration not reset");
assertTrue(newConfig instanceof XmlConfiguration, "Reconfiguration failed");
context = LoggerContext.getContext(false);
final Configuration sameConfig = context.getConfiguration();
assertSame(newConfig, sameConfig, "Configuration should not have been reset");
}
use of org.apache.logging.log4j.core.config.xml.XmlConfiguration in project logging-log4j2 by apache.
the class NestedLoggerConfigTest method loadConfiguration.
private Configuration loadConfiguration(String resourcePath) throws IOException {
try (InputStream in = getClass().getClassLoader().getResourceAsStream(resourcePath)) {
Configuration configuration = new XmlConfiguration(new LoggerContext("test"), new ConfigurationSource(in));
configuration.initialize();
configuration.start();
return configuration;
}
}
use of org.apache.logging.log4j.core.config.xml.XmlConfiguration in project iaf by ibissource.
the class IbisLoggerConfigurationFactory method getConfiguration.
@Override
public Configuration getConfiguration(LoggerContext loggerContext, ConfigurationSource source) {
try {
setLogDir();
setLevel();
String configuration = readLog4jConfiguration(source.getInputStream());
Properties properties = getProperties();
// Look for properties in the Log4J2 XML
Matcher m = Pattern.compile("\\$\\{(?:ctx:)?([^}]*)\\}").matcher(configuration);
Map<String, String> substitutions = new HashMap<>();
while (m.find()) {
String key = m.group(1);
String value = resolveValueRecursively(properties, key);
if (value != null) {
substitutions.put(key, value);
}
}
// Only add the substituted variables to the ThreadContext
ThreadContext.putAll(substitutions);
return new // We have to 'reset' the source as the old stream has been read.
XmlConfiguration(// We have to 'reset' the source as the old stream has been read.
loggerContext, // We have to 'reset' the source as the old stream has been read.
source.resetInputStream()) {
// Add hashcode to toString() so we can differentiate the XmlConfigurations in the startup log
@Override
public String toString() {
return this.getClass().getCanonicalName() + "@" + Integer.toHexString(this.hashCode()) + "[location=" + getConfigurationSource() + "]";
}
};
} catch (IOException e) {
System.err.println(LOG_PREFIX + "unable to configure Log4J2");
throw new IllegalStateException(LOG_PREFIX + "unable to configure Log4J2", e);
}
}
Aggregations