本文整理汇总了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();
}
}
}
示例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();
}
示例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();
}
示例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);
}
示例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();
}
示例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();
}
示例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);
}
示例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);
}
示例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();
}
}