當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。