本文整理汇总了Java中org.apache.logging.log4j.core.config.Configuration.getAppenders方法的典型用法代码示例。如果您正苦于以下问题:Java Configuration.getAppenders方法的具体用法?Java Configuration.getAppenders怎么用?Java Configuration.getAppenders使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.logging.log4j.core.config.Configuration
的用法示例。
在下文中一共展示了Configuration.getAppenders方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testLogReconfiguration
import org.apache.logging.log4j.core.config.Configuration; //导入方法依赖的package包/类
/**
* This test asserts that after re-configuration of the log engine the total appenders are
* different. The 'comparison' will be done between:
*
* - default config (src/main/resources/log4j2.xml)
* - alternative config (src/test/resources/xml/config-for-LogManagerTest.xml)
*/
@Test (groups = { GROUP_CHANGE_CONFIG }, description = "Validate the numbers of Appenders associated with the LoggerContext")
public void testLogReconfiguration() {
LOGGER.debug("About to test re-configuration of the logger context");
final String pathToAlternativeLogConfig = "src/test/resources/config/log/config-for-LogManagerTest.xml";
LoggerContext loggerContext = LoggerContext.getContext(false);
Configuration configuration = loggerContext.getConfiguration();
Map<String, Appender> appenderMap = configuration.getAppenders();
Assert.assertTrue(appenderMap.size() == 1, "Expected 1 appender");
Assert.assertTrue(appenderMap.containsKey("console"));
LogManager.initializeLogging(pathToAlternativeLogConfig);
// Refresh reference of configuration as it changed
configuration = loggerContext.getConfiguration();
appenderMap = configuration.getAppenders();
Assert.assertTrue(appenderMap.size() == 2, "Expected 2 appenders");
Assert.assertTrue(appenderMap.containsKey("console"));
Assert.assertTrue(appenderMap.containsKey("filterAppender"));
}
示例2: testPropertiesConfiguration
import org.apache.logging.log4j.core.config.Configuration; //导入方法依赖的package包/类
@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!");
}
示例3: testPropertiesConfiguration
import org.apache.logging.log4j.core.config.Configuration; //导入方法依赖的package包/类
@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() == 1);
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!");
}
示例4: testPropertiesConfiguration
import org.apache.logging.log4j.core.config.Configuration; //导入方法依赖的package包/类
@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());
assertEquals("Incorrect level " + logger.getLevel(), Level.DEBUG, logger.getLevel());
logger.debug("Welcome to Log4j!");
}
示例5: testPropertiesConfiguration
import org.apache.logging.log4j.core.config.Configuration; //导入方法依赖的package包/类
@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!");
}
示例6: getMemoryAppender
import org.apache.logging.log4j.core.config.Configuration; //导入方法依赖的package包/类
/**
* Return the one and only memory appender
*/
public static MemoryAppender getMemoryAppender() {
MemoryAppender memoryAppender = null;
final LoggerContext ctx = (org.apache.logging.log4j.core.LoggerContext) LogManager.getContext(StartServlet.class.getClassLoader(), false);
final Configuration config = (Configuration) ctx.getConfiguration();
Map<String, Appender> appenders = config.getAppenders();
if (appenders != null) {
memoryAppender = (MemoryAppender) appenders.get("MEMORY");
}
return memoryAppender;
}
示例7: testConfiguration
import org.apache.logging.log4j.core.config.Configuration; //导入方法依赖的package包/类
@Test
public void testConfiguration() throws Exception {
final LoggerContext ctx = (LoggerContext) LogManager.getContext();
final Configuration config = ctx.getConfiguration();
final Map<String, Appender> appenders = config.getAppenders();
assertTrue(appenders.containsKey("JMSQueue"));
}
示例8: testConfig
import org.apache.logging.log4j.core.config.Configuration; //导入方法依赖的package包/类
@Test
public void testConfig() {
final LoggerContext ctx = Configurator.initialize("Test1", "target/test-classes/log4j2-mapfilter.xml");
final Configuration config = ctx.getConfiguration();
final Filter filter = config.getFilter();
assertNotNull("No MapFilter", filter);
assertTrue("Not a MapFilter", filter instanceof MapFilter);
final MapFilter mapFilter = (MapFilter) filter;
assertFalse("Should not be And filter", mapFilter.isAnd());
final Map<String, List<String>> map = mapFilter.getMap();
assertNotNull("No Map", map);
assertTrue("No elements in Map", map.size() != 0);
assertTrue("Incorrect number of elements in Map", map.size() == 1);
assertTrue("Map does not contain key eventId", map.containsKey("eventId"));
assertTrue("List does not contain 2 elements", map.get("eventId").size() == 2);
final Logger logger = LogManager.getLogger(MapFilterTest.class);
final Map<String, String> eventMap = new HashMap<String, String>();
eventMap.put("eventId", "Login");
logger.debug(new MapMessage(eventMap));
final Map<String,Appender> appenders = config.getAppenders();
final Appender app = appenders.get("LIST");
assertNotNull("No List appender", app);
final List<String> msgs = ((ListAppender) app).getMessages();
assertNotNull("No messages", msgs);
assertTrue("No messages", msgs.size() > 0);
}
示例9: validate
import org.apache.logging.log4j.core.config.Configuration; //导入方法依赖的package包/类
private void validate(final Configuration config) {
assertNotNull(config);
assertNotNull(config.getName());
assertFalse(config.getName().isEmpty());
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() == 2);
final KafkaAppender kafkaAppender = (KafkaAppender) appenders.get("Kafka");
final GelfLayout gelfLayout = (GelfLayout) kafkaAppender.getLayout();
final Map<String, LoggerConfig> loggers = config.getLoggers();
assertNotNull(loggers);
assertTrue("Incorrect number of LoggerConfigs: " + loggers.size(), loggers.size() == 2);
final LoggerConfig rootLoggerConfig = loggers.get("");
assertEquals(Level.ERROR, rootLoggerConfig.getLevel());
assertFalse(rootLoggerConfig.isIncludeLocation());
final LoggerConfig loggerConfig = loggers.get("org.apache.logging.log4j");
assertEquals(Level.DEBUG, loggerConfig.getLevel());
assertTrue(loggerConfig.isIncludeLocation());
final Filter filter = config.getFilter();
assertNotNull("No Filter", filter);
assertTrue("Not a Threshold Filter", filter instanceof ThresholdFilter);
final List<CustomLevelConfig> customLevels = config.getCustomLevels();
assertNotNull("No CustomLevels", filter);
assertEquals(1, customLevels.size());
final CustomLevelConfig customLevel = customLevels.get(0);
assertEquals("Panic", customLevel.getLevelName());
assertEquals(17, customLevel.getIntLevel());
final Logger logger = LogManager.getLogger(getClass());
logger.info("Welcome to Log4j!");
}
示例10: testLookup2
import org.apache.logging.log4j.core.config.Configuration; //导入方法依赖的package包/类
@Test
public void testLookup2() throws Exception {
ContextAnchor.THREAD_CONTEXT.remove();
final ServletContext servletContext = new MockServletContext();
servletContext.setAttribute("TestAttr", "AttrValue");
servletContext.setInitParameter("myapp.logdir", "target");
servletContext.setAttribute("Name1", "Ben");
servletContext.setInitParameter("Name2", "Jerry");
servletContext.setInitParameter("log4jConfiguration", "WEB-INF/classes/log4j-webvar.xml");
final Log4jWebLifeCycle initializer = WebLoggerContextUtils.getWebLifeCycle(servletContext);
initializer.start();
initializer.setLoggerContext();
final LoggerContext ctx = ContextAnchor.THREAD_CONTEXT.get();
assertNotNull("No LoggerContext", ctx);
assertNotNull("No ServletContext", ctx.getExternalContext());
final Configuration config = ctx.getConfiguration();
assertNotNull("No Configuration", config);
final Map<String, Appender> appenders = config.getAppenders();
for (final Map.Entry<String, Appender> entry : appenders.entrySet()) {
if (entry.getKey().equals("file")) {
final FileAppender fa = (FileAppender) entry.getValue();
assertEquals("target/myapp.log", fa.getFileName());
}
}
initializer.stop();
ContextAnchor.THREAD_CONTEXT.remove();
}
示例11: validate
import org.apache.logging.log4j.core.config.Configuration; //导入方法依赖的package包/类
private void validate(final Configuration config) {
assertNotNull(config);
assertNotNull(config.getName());
assertFalse(config.getName().isEmpty());
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 ConsoleAppender consoleAppender = (ConsoleAppender)appenders.get("Stdout");
final PatternLayout gelfLayout = (PatternLayout)consoleAppender.getLayout();
final Map<String, LoggerConfig> loggers = config.getLoggers();
assertNotNull(loggers);
assertTrue("Incorrect number of LoggerConfigs: " + loggers.size(), loggers.size() == 2);
final LoggerConfig rootLoggerConfig = loggers.get("");
assertEquals(Level.ERROR, rootLoggerConfig.getLevel());
assertFalse(rootLoggerConfig.isIncludeLocation());
final LoggerConfig loggerConfig = loggers.get("org.apache.logging.log4j");
assertEquals(Level.DEBUG, loggerConfig.getLevel());
assertTrue(loggerConfig.isIncludeLocation());
final Filter filter = config.getFilter();
assertNotNull("No Filter", filter);
assertTrue("Not a Threshold Filter", filter instanceof ThresholdFilter);
final List<CustomLevelConfig> customLevels = config.getCustomLevels();
assertNotNull("No CustomLevels", filter);
assertEquals(1, customLevels.size());
final CustomLevelConfig customLevel = customLevels.get(0);
assertEquals("Panic", customLevel.getLevelName());
assertEquals(17, customLevel.getIntLevel());
final Logger logger = LogManager.getLogger(getClass());
logger.info("Welcome to Log4j!");
}