当前位置: 首页>>代码示例>>Java>>正文


Java Configuration.getAppender方法代码示例

本文整理汇总了Java中org.apache.logging.log4j.core.config.Configuration.getAppender方法的典型用法代码示例。如果您正苦于以下问题:Java Configuration.getAppender方法的具体用法?Java Configuration.getAppender怎么用?Java Configuration.getAppender使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.logging.log4j.core.config.Configuration的用法示例。


在下文中一共展示了Configuration.getAppender方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testSystemProperties1

import org.apache.logging.log4j.core.config.Configuration; //导入方法依赖的package包/类
@Test
public void testSystemProperties1() throws Exception {
       final String tempFileName = System.getProperty("java.io.tmpdir") + "/hadoop.log";
       final Path tempFilePath = new File(tempFileName).toPath();
       Files.deleteIfExists(tempFilePath);
       try {
           final Configuration configuration = getConfiguration("config-1.2/log4j-system-properties-1.properties");
           final RollingFileAppender appender = configuration.getAppender("RFA");
		appender.stop(10, TimeUnit.SECONDS);
           System.out.println("expected: " + tempFileName + " Actual: " + appender.getFileName());
           assertEquals(tempFileName, appender.getFileName());
       } finally {
		try {
			Files.deleteIfExists(tempFilePath);
		} catch (FileSystemException e) {
			e.printStackTrace();
		}
       }
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:20,代码来源:Log4j1ConfigurationFactoryTest.java

示例2: testRollingFileAppender

import org.apache.logging.log4j.core.config.Configuration; //导入方法依赖的package包/类
private void testRollingFileAppender(final String configResource, final String name, final String filePattern) throws URISyntaxException {
	final Configuration configuration = getConfiguration(configResource);
	final Appender appender = configuration.getAppender(name);
	assertNotNull(appender);
	assertEquals(name, appender.getName());
	assertTrue(appender.getClass().getName(), appender instanceof RollingFileAppender);
	final RollingFileAppender rfa = (RollingFileAppender) appender;
	assertEquals("target/hadoop.log", rfa.getFileName());
	assertEquals(filePattern, rfa.getFilePattern());
	final TriggeringPolicy triggeringPolicy = rfa.getTriggeringPolicy();
	assertNotNull(triggeringPolicy);
	assertTrue(triggeringPolicy.getClass().getName(), triggeringPolicy instanceof CompositeTriggeringPolicy);
	final CompositeTriggeringPolicy ctp = (CompositeTriggeringPolicy) triggeringPolicy;
	final TriggeringPolicy[] triggeringPolicies = ctp.getTriggeringPolicies();
	assertEquals(1, triggeringPolicies.length);
	final TriggeringPolicy tp = triggeringPolicies[0];
	assertTrue(tp.getClass().getName(), tp instanceof SizeBasedTriggeringPolicy);
	final SizeBasedTriggeringPolicy sbtp = (SizeBasedTriggeringPolicy) tp;
	assertEquals(256 * 1024 * 1024, sbtp.getMaxFileSize());
	final RolloverStrategy rolloverStrategy = rfa.getManager().getRolloverStrategy();
	assertTrue(rolloverStrategy.getClass().getName(), rolloverStrategy instanceof DefaultRolloverStrategy);
	final DefaultRolloverStrategy drs = (DefaultRolloverStrategy) rolloverStrategy;
	assertEquals(20, drs.getMaxIndex());
	configuration.start();
	configuration.stop();
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:27,代码来源:Log4j1ConfigurationFactoryTest.java

示例3: testDailyRollingFileAppender

import org.apache.logging.log4j.core.config.Configuration; //导入方法依赖的package包/类
private void testDailyRollingFileAppender(final String configResource, final String name, final String filePattern) throws URISyntaxException {
	final Configuration configuration = getConfiguration(configResource);
	final Appender appender = configuration.getAppender(name);
	assertNotNull(appender);
	assertEquals(name, appender.getName());
	assertTrue(appender.getClass().getName(), appender instanceof RollingFileAppender);
	final RollingFileAppender rfa = (RollingFileAppender) appender;
	assertEquals("target/hadoop.log", rfa.getFileName());
	assertEquals(filePattern, rfa.getFilePattern());
	final TriggeringPolicy triggeringPolicy = rfa.getTriggeringPolicy();
	assertNotNull(triggeringPolicy);
	assertTrue(triggeringPolicy.getClass().getName(), triggeringPolicy instanceof CompositeTriggeringPolicy);
	final CompositeTriggeringPolicy ctp = (CompositeTriggeringPolicy) triggeringPolicy;
	final TriggeringPolicy[] triggeringPolicies = ctp.getTriggeringPolicies();
	assertEquals(1, triggeringPolicies.length);
	final TriggeringPolicy tp = triggeringPolicies[0];
	assertTrue(tp.getClass().getName(), tp instanceof TimeBasedTriggeringPolicy);
	final TimeBasedTriggeringPolicy tbtp = (TimeBasedTriggeringPolicy) tp;
	assertEquals(1, tbtp.getInterval());
	final RolloverStrategy rolloverStrategy = rfa.getManager().getRolloverStrategy();
	assertTrue(rolloverStrategy.getClass().getName(), rolloverStrategy instanceof DefaultRolloverStrategy);
	final DefaultRolloverStrategy drs = (DefaultRolloverStrategy) rolloverStrategy;
	assertEquals(Integer.MAX_VALUE, drs.getMaxIndex());
	configuration.start();
	configuration.stop();
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:27,代码来源:Log4j1ConfigurationFactoryTest.java

示例4: testConfiguration

import org.apache.logging.log4j.core.config.Configuration; //导入方法依赖的package包/类
@Test
public void testConfiguration() {
    final Configuration configuration = context.getConfiguration();
    assertNotNull(configuration);
    final FileAppender appender = configuration.getAppender("info");
    assertNotNull(appender);
    final CompositeFilter compFilter = (CompositeFilter) appender.getFilter();
    assertNotNull(compFilter);
    final Filter[] filters = compFilter.getFiltersArray();
    assertNotNull(filters);
    boolean foundLevel = false;
    for (final Filter filter : filters) {
        final ThresholdFilter tFilter = (ThresholdFilter) filter;
        if (infom1Level.equals(tFilter.getLevel())) {
            foundLevel = true;
            break;
        }
    }
    Assert.assertTrue("Level not found: " + infom1Level, foundLevel);
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:21,代码来源:CustomLevelsWithFiltersTest.java

示例5: testConsole

import org.apache.logging.log4j.core.config.Configuration; //导入方法依赖的package包/类
private Layout<?> testConsole(final String configResource) throws Exception {
    final Configuration configuration = getConfiguration(configResource);
    final String name = "Console";
    final ConsoleAppender appender = configuration.getAppender(name);
    assertNotNull("Missing appender '" + name + "' in configuration " + configResource + " → " + configuration,
            appender);
    assertEquals(Target.SYSTEM_ERR, appender.getTarget());
    //
    final LoggerConfig loggerConfig = configuration.getLoggerConfig("com.example.foo");
    assertNotNull(loggerConfig);
    assertEquals(Level.DEBUG, loggerConfig.getLevel());
    configuration.start();
    configuration.stop();
    return appender.getLayout();
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:16,代码来源:Log4j1ConfigurationFactoryTest.java

示例6: testFile

import org.apache.logging.log4j.core.config.Configuration; //导入方法依赖的package包/类
private Layout<?> testFile(final String configResource) throws Exception {
	final Configuration configuration = getConfiguration(configResource);
	final FileAppender appender = configuration.getAppender("File");
	assertNotNull(appender);
	assertEquals("target/mylog.txt", appender.getFileName());
	//
	final LoggerConfig loggerConfig = configuration.getLoggerConfig("com.example.foo");
	assertNotNull(loggerConfig);
	assertEquals(Level.DEBUG, loggerConfig.getLevel());
	configuration.start();
	configuration.stop();
	return appender.getLayout();
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:14,代码来源:Log4j1ConfigurationFactoryTest.java

示例7: testNullAppender

import org.apache.logging.log4j.core.config.Configuration; //导入方法依赖的package包/类
@Test
public void testNullAppender() throws Exception {
	final Configuration configuration = getConfiguration("config-1.2/log4j-NullAppender.properties");
	final Appender appender = configuration.getAppender("NullAppender");
	assertNotNull(appender);
	assertEquals("NullAppender", appender.getName());
	assertTrue(appender.getClass().getName(), appender instanceof NullAppender);
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:9,代码来源:Log4j1ConfigurationFactoryTest.java

示例8: testSystemProperties2

import org.apache.logging.log4j.core.config.Configuration; //导入方法依赖的package包/类
@Test
public void testSystemProperties2() throws Exception {
	final Configuration configuration = getConfiguration("config-1.2/log4j-system-properties-2.properties");
	final RollingFileAppender appender = configuration.getAppender("RFA");
	assertEquals("${java.io.tmpdir}/hadoop.log", appender.getFileName());
	appender.stop(10, TimeUnit.SECONDS);
	Path path = new File(appender.getFileName()).toPath();
       Files.deleteIfExists(path);
       path = new File("${java.io.tmpdir}").toPath();
       Files.deleteIfExists(path);
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:12,代码来源:Log4j1ConfigurationFactoryTest.java

示例9: testAppender

import org.apache.logging.log4j.core.config.Configuration; //导入方法依赖的package包/类
@Test
public void testAppender() throws Exception {
    ContextAnchor.THREAD_CONTEXT.remove();
    final ServletContext servletContext = new MockServletContext();
    servletContext.setAttribute("TestAttr", "AttrValue");
    servletContext.setInitParameter("TestParam", "ParamValue");
    servletContext.setAttribute("Name1", "Ben");
    servletContext.setInitParameter("Name2", "Jerry");
    servletContext.setInitParameter(Log4jWebSupport.LOG4J_CONFIG_LOCATION, CONFIG);
    final Log4jWebLifeCycle initializer = WebLoggerContextUtils.getWebLifeCycle(servletContext);
    try {
        initializer.start();
        initializer.setLoggerContext();
        final LoggerContext ctx = ContextAnchor.THREAD_CONTEXT.get();
        assertNotNull("No LoggerContext", ctx);
        assertNotNull("No ServletContext", ctx.getExternalContext());
        final Configuration configuration = ctx.getConfiguration();
        assertNotNull("No configuration", configuration);
        final Appender appender = configuration.getAppender("Servlet");
        assertNotNull("No ServletAppender", appender);
        final Logger logger = LogManager.getLogger("Test");
        logger.info("This is a test");
        logger.error("This is a test 2", new IllegalStateException().fillInStackTrace());
    } catch (final IllegalStateException e) {
        fail("Failed to initialize Log4j properly." + e.getMessage());
    } finally {
        initializer.stop();
        ContextAnchor.THREAD_CONTEXT.remove();
    }
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:31,代码来源:ServletAppenderTest.java


注:本文中的org.apache.logging.log4j.core.config.Configuration.getAppender方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。