use of org.apache.logging.log4j.core.config.Configuration in project logging-log4j2 by apache.
the class PropertiesConfigurationTest method testPropertiesConfiguration.
@Test
public void testPropertiesConfiguration() {
final Configuration config = context.getConfiguration();
assertNotNull("No configuration created", config);
assertEquals("Incorrect State: " + config.getState(), config.getState(), LifeCycle.State.STARTED);
final Map<String, Appender> appenders = config.getAppenders();
assertNotNull(appenders);
assertTrue("Incorrect number of Appenders: " + appenders.size(), appenders.size() == 1);
final Map<String, LoggerConfig> loggers = config.getLoggers();
assertNotNull(loggers);
assertTrue("Incorrect number of LoggerConfigs: " + loggers.size(), loggers.size() == 2);
final Filter filter = config.getFilter();
assertNotNull("No Filter", filter);
assertTrue("Not a Threshold Filter", filter instanceof ThresholdFilter);
final Logger logger = LogManager.getLogger(getClass());
logger.info("Welcome to Log4j!");
}
use of org.apache.logging.log4j.core.config.Configuration in project logging-log4j2 by apache.
the class RollingFilePropertiesTest method testPropertiesConfiguration.
@Test
public void testPropertiesConfiguration() {
final Configuration config = context.getConfiguration();
assertNotNull("No configuration created", config);
assertEquals("Incorrect State: " + config.getState(), config.getState(), LifeCycle.State.STARTED);
final Map<String, Appender> appenders = config.getAppenders();
assertNotNull(appenders);
assertTrue("Incorrect number of Appenders: " + appenders.size(), appenders.size() == 3);
final Map<String, LoggerConfig> loggers = config.getLoggers();
assertNotNull(loggers);
assertTrue("Incorrect number of LoggerConfigs: " + loggers.size(), loggers.size() == 2);
final Filter filter = config.getFilter();
assertNotNull("No Filter", filter);
assertTrue("Not a Threshold Filter", filter instanceof ThresholdFilter);
final Logger logger = LogManager.getLogger(getClass());
logger.info("Welcome to Log4j!");
}
use of org.apache.logging.log4j.core.config.Configuration in project logging-log4j2 by apache.
the class XmlConfigurationPropsTest method testWithConfigProp.
@Test
public void testWithConfigProp() {
System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
System.setProperty("log4j.level", "warn");
try {
final LoggerContext ctx = LoggerContext.getContext();
ctx.reconfigure();
final Configuration config = ctx.getConfiguration();
assertTrue("Configuration is not an XmlConfiguration", config instanceof XmlConfiguration);
} finally {
System.clearProperty("log4j.level");
}
}
use of org.apache.logging.log4j.core.config.Configuration in project logging-log4j2 by apache.
the class XmlConfigurationPropsTest method testWithProps.
@Test
public void testWithProps() {
System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
System.setProperty("log4j.level", "warn");
System.setProperty("log.level", "warn");
try {
final LoggerContext ctx = LoggerContext.getContext();
ctx.reconfigure();
final Configuration config = ctx.getConfiguration();
assertTrue("Configuration is not an XmlConfiguration", config instanceof XmlConfiguration);
} finally {
System.clearProperty("log4j.level");
System.clearProperty("log.level");
}
}
use of org.apache.logging.log4j.core.config.Configuration in project logging-log4j2 by apache.
the class LoggerContextAdmin method setConfigText.
@Override
public void setConfigText(final String configText, final String charsetName) {
LOGGER.debug("---------");
LOGGER.debug("Remote request to reconfigure from config text.");
try {
final InputStream in = new ByteArrayInputStream(configText.getBytes(charsetName));
final ConfigurationSource source = new ConfigurationSource(in);
final Configuration updated = ConfigurationFactory.getInstance().getConfiguration(loggerContext, source);
loggerContext.start(updated);
LOGGER.debug("Completed remote request to reconfigure from config text.");
} catch (final Exception ex) {
final String msg = "Could not reconfigure from config text";
LOGGER.error(msg, ex);
throw new IllegalArgumentException(msg, ex);
}
}
Aggregations