org.apache.logging.log4j.core.config.Configuration.getName()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(15.9k)|赞(0)|评价(0)|浏览(160)

本文整理了Java中org.apache.logging.log4j.core.config.Configuration.getName()方法的一些代码示例,展示了Configuration.getName()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Configuration.getName()方法的具体详情如下:
包路径:org.apache.logging.log4j.core.config.Configuration
类名称:Configuration
方法名:getName

Configuration.getName介绍

[英]Returns the configuration name.
[中]返回配置名称。

代码示例

代码示例来源:origin: org.apache.logging.log4j/log4j-core

@Test
public void testNoLoggers() throws Exception {
  ctx = Configurator.initialize("Test1", "bad/log4j-loggers.xml");
  LogManager.getLogger("org.apache.test.TestConfigurator");
  final Configuration config = ctx.getConfiguration();
  assertNotNull("No configuration", config);
  final String name = DefaultConfiguration.DEFAULT_NAME + "@" + Integer.toHexString(config.hashCode());
  assertEquals("Unexpected Configuration.", name, config.getName());
}

代码示例来源:origin: org.apache.logging.log4j/log4j-core

@BeforeClass
public static void setupClass() {
  final File file = new File(STATUS_LOG);
  file.delete();
  System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
  final LoggerContext ctx = LoggerContext.getContext();
  final Configuration config = ctx.getConfiguration();
  if (config instanceof XmlConfiguration) {
    final String name = config.getName();
    if (name == null || !name.equals("XMLConfigTest")) {
      ctx.reconfigure();
    }
  } else {
    ctx.reconfigure();
  }
}

代码示例来源:origin: org.apache.logging.log4j/log4j-core

@Test
public void testBadFileName() throws Exception {
  final StringBuilder dir = new StringBuilder("/VeryLongDirectoryName");
  for (final String element : CHARS) {
    dir.append(element);
    dir.append(element.toUpperCase());
  }
  final String value = FILESEP.equals("/") ? dir.toString() + "/test.log" : "1:/target/bad:file.log";
  System.setProperty("testfile", value);
  ctx = Configurator.initialize("Test1", "bad/log4j-badfilename.xml");
  LogManager.getLogger("org.apache.test.TestConfigurator");
  final Configuration config = ctx.getConfiguration();
  assertNotNull("No configuration", config);
  assertEquals("Unexpected Configuration", "XMLConfigTest", config.getName());
  assertThat(config.getAppenders(), hasSize(equalTo(2)));
}

代码示例来源:origin: org.apache.logging.log4j/log4j-core

@Test
public void testBadLayout() throws Exception {
  ctx = Configurator.initialize("Test1", "bad/log4j-badlayout.xml");
  LogManager.getLogger("org.apache.test.TestConfigurator");
  final Configuration config = ctx.getConfiguration();
  assertNotNull("No configuration", config);
  assertEquals("Unexpected Configuration", "XMLConfigTest", config.getName());
}

代码示例来源:origin: org.apache.logging.log4j/log4j-core

Configuration config = ctx.getConfiguration();
assertNotNull("No configuration", config);
assertEquals("Incorrect Configuration.", CONFIG_NAME, config.getName());
final Map<String, Appender> map = config.getAppenders();
assertNotNull("Appenders map should not be null.", map);
Configurator.shutdown(ctx);
config = ctx.getConfiguration();
assertEquals("Unexpected Configuration.", NullConfiguration.NULL_NAME, config.getName());

代码示例来源:origin: org.apache.logging.log4j/log4j-core

@Test
public void testInitialize_Name_ClassLoader_URI() throws Exception {
  ctx = Configurator.initialize("Test1", null, new File("target/test-classes/log4j2-config.xml").toURI());
  LogManager.getLogger("org.apache.test.TestConfigurator");
  Configuration config = ctx.getConfiguration();
  assertNotNull("No configuration", config);
  assertEquals("Incorrect Configuration.", CONFIG_NAME, config.getName());
  final Map<String, Appender> map = config.getAppenders();
  assertNotNull("Appenders map should not be null.", map);
  assertThat(map, hasSize(greaterThan(0)));
  assertThat("Wrong configuration", map, hasKey("List"));
  Configurator.shutdown(ctx);
  config = ctx.getConfiguration();
  assertEquals("Unexpected Configuration.", NullConfiguration.NULL_NAME, config.getName());
}

代码示例来源:origin: org.apache.logging.log4j/log4j-core

@Test
public void testFromClassPathProperty() throws Exception {
  System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, "classpath:log4j2-config.xml");
  ctx = Configurator.initialize("Test1", null);
  LogManager.getLogger("org.apache.test.TestConfigurator");
  Configuration config = ctx.getConfiguration();
  assertNotNull("No configuration", config);
  assertEquals("Incorrect Configuration.", CONFIG_NAME, config.getName());
  final Map<String, Appender> map = config.getAppenders();
  assertNotNull("Appenders map should not be null.", map);
  assertThat(map, hasSize(greaterThan(0)));
  assertThat("Wrong configuration", map, hasKey("List"));
  Configurator.shutdown(ctx);
  config = ctx.getConfiguration();
  assertEquals("Unexpected Configuration.", NullConfiguration.NULL_NAME, config.getName());
}

代码示例来源:origin: org.apache.logging.log4j/log4j-core

@Test
public void testInitialize_InputStream_File() throws Exception {
  final File file = new File("target/test-classes/log4j2-config.xml");
  final InputStream is = new FileInputStream(file);
  final ConfigurationSource source = new ConfigurationSource(is, file);
  ctx = Configurator.initialize(null, source);
  LogManager.getLogger("org.apache.test.TestConfigurator");
  Configuration config = ctx.getConfiguration();
  assertNotNull("No configuration", config);
  assertEquals("Incorrect Configuration.", CONFIG_NAME, config.getName());
  final Map<String, Appender> map = config.getAppenders();
  assertNotNull("Appenders map should not be null.", map);
  assertThat(map, hasSize(greaterThan(0)));
  assertThat("Wrong configuration", map, hasKey("List"));
  Configurator.shutdown(ctx);
  config = ctx.getConfiguration();
  assertEquals("Unexpected Configuration.", NullConfiguration.NULL_NAME, config.getName());
}

代码示例来源:origin: org.apache.logging.log4j/log4j-core

@Test
public void testInitialize_Name_LocationName() throws Exception {
  ctx = Configurator.initialize("Test1", "log4j2-config.xml");
  LogManager.getLogger("org.apache.test.TestConfigurator");
  Configuration config = ctx.getConfiguration();
  assertNotNull("No configuration", config);
  assertEquals("Incorrect Configuration.", CONFIG_NAME, config.getName());
  final Map<String, Appender> map = config.getAppenders();
  assertNotNull("Appenders map should not be null.", map);
  assertThat(map, hasSize(greaterThan(0)));
  assertThat("Wrong configuration", map, hasKey("List"));
  Configurator.shutdown(ctx);
  config = ctx.getConfiguration();
  assertEquals("Unexpected Configuration.", NullConfiguration.NULL_NAME, config.getName());
}

代码示例来源:origin: org.apache.logging.log4j/log4j-core

@Test
public void testFromClassPathWithClassPathPrefix() throws Exception {
  ctx = Configurator.initialize("Test1", "classpath:log4j2-config.xml");
  LogManager.getLogger("org.apache.test.TestConfigurator");
  Configuration config = ctx.getConfiguration();
  assertNotNull("No configuration", config);
  assertEquals("Incorrect Configuration.", CONFIG_NAME, config.getName());
  final Map<String, Appender> map = config.getAppenders();
  assertNotNull("Appenders map should not be null.", map);
  assertThat(map, hasSize(greaterThan(0)));
  assertThat("Wrong configuration", map, hasKey("List"));
  Configurator.shutdown(ctx);
  config = ctx.getConfiguration();
  assertEquals("Incorrect Configuration.", NullConfiguration.NULL_NAME, config.getName());
}

代码示例来源:origin: org.apache.logging.log4j/log4j-core

@Test
public void testByName() throws Exception {
  ctx = Configurator.initialize("-config", null);
  LogManager.getLogger("org.apache.test.TestConfigurator");
  Configuration config = ctx.getConfiguration();
  assertNotNull("No configuration", config);
  assertEquals("Incorrect Configuration.", CONFIG_NAME, config.getName());
  final Map<String, Appender> map = config.getAppenders();
  assertNotNull("Appenders map should not be null.", map);
  assertThat(map, hasSize(greaterThan(0)));
  assertThat("Wrong configuration", map, hasKey("List"));
  Configurator.shutdown(ctx);
  config = ctx.getConfiguration();
  assertEquals("Unexpected Configuration.", NullConfiguration.NULL_NAME, config.getName());
}

代码示例来源:origin: org.apache.logging.log4j/log4j-core

@Test
public void testInitialize_Name_PathName() throws Exception {
  ctx = Configurator.initialize("Test1", "target/test-classes/log4j2-config.xml");
  LogManager.getLogger("org.apache.test.TestConfigurator");
  Configuration config = ctx.getConfiguration();
  assertNotNull("No configuration", config);
  assertEquals("Incorrect Configuration.", CONFIG_NAME, config.getName());
  final Map<String, Appender> map = config.getAppenders();
  assertNotNull("Appenders map should not be null.", map);
  assertThat(map, hasSize(greaterThan(0)));
  assertThat("Wrong configuration", map, hasKey("List"));
  Configurator.shutdown(ctx);
  config = ctx.getConfiguration();
  assertEquals("Unexpected Configuration.", NullConfiguration.NULL_NAME, config.getName());
}

代码示例来源:origin: org.apache.logging.log4j/log4j-core

@Test
public void testFromClassPathWithClassLoaderPrefix() throws Exception {
  ctx = Configurator.initialize("Test1", "classloader:log4j2-config.xml");
  LogManager.getLogger("org.apache.test.TestConfigurator");
  Configuration config = ctx.getConfiguration();
  assertNotNull("No configuration", config);
  assertEquals("Incorrect Configuration.", CONFIG_NAME, config.getName());
  final Map<String, Appender> map = config.getAppenders();
  assertNotNull("Appenders map should not be null.", map);
  assertThat(map, hasSize(greaterThan(0)));
  assertThat("Wrong configuration", map, hasKey("List"));
  Configurator.shutdown(ctx);
  config = ctx.getConfiguration();
  assertEquals("Incorrect Configuration.", NullConfiguration.NULL_NAME, config.getName());
}

代码示例来源:origin: org.apache.logging.log4j/log4j-core

@Test
public void testInitialize_NullClassLoader_ConfigurationSourceWithInputStream_NoId() throws Exception {
  final InputStream is = new FileInputStream("target/test-classes/log4j2-config.xml");
  final ConfigurationSource source =
    new ConfigurationSource(is);
  ctx = Configurator.initialize(null, source);
  LogManager.getLogger("org.apache.test.TestConfigurator");
  Configuration config = ctx.getConfiguration();
  assertNotNull("No configuration", config);
  assertEquals("Incorrect Configuration.", CONFIG_NAME, config.getName());
  final Map<String, Appender> map = config.getAppenders();
  assertNotNull("Appenders map should not be null.", map);
  assertThat(map, hasSize(greaterThan(0)));
  assertThat("Wrong configuration", map, hasKey("List"));
  Configurator.shutdown(ctx);
  config = ctx.getConfiguration();
  assertEquals("Unexpected Configuration.", NullConfiguration.NULL_NAME, config.getName());
}

代码示例来源:origin: org.apache.logging.log4j/log4j-core

@Test
public void testBadFilterParam() throws Exception {
  ctx = Configurator.initialize("Test1", "bad/log4j-badfilterparam.xml");
  LogManager.getLogger("org.apache.test.TestConfigurator");
  final Configuration config = ctx.getConfiguration();
  assertNotNull("No configuration", config);
  assertEquals("Unexpected Configuration", "XMLConfigTest", config.getName());
  final LoggerConfig lcfg = config.getLoggerConfig("org.apache.logging.log4j.test1");
  assertNotNull("No Logger", lcfg);
  final Filter filter = lcfg.getFilter();
  assertNull("Unexpected Filter", filter);
}

代码示例来源:origin: org.apache.logging.log4j/log4j-core

@Test
public void testBadStatus() throws Exception {
  ctx = Configurator.initialize("Test1", "bad/log4j-status.xml");
  LogManager.getLogger("org.apache.test.TestConfigurator");
  final Configuration config = ctx.getConfiguration();
  assertNotNull("No configuration", config);
  assertEquals("Unexpected Configuration", "XMLConfigTest", config.getName());
  final LoggerConfig root = config.getLoggerConfig("");
  assertNotNull("No Root Logger", root);
  assertTrue("Expected error level, was " + root.getLevel(), Level.ERROR == root.getLevel());
}

代码示例来源:origin: org.apache.logging.log4j/log4j-core

@Test
public void testNoFilters() throws Exception {
  ctx = Configurator.initialize("Test1", "bad/log4j-nofilter.xml");
  LogManager.getLogger("org.apache.test.TestConfigurator");
  final Configuration config = ctx.getConfiguration();
  assertNotNull("No configuration", config);
  assertEquals("Unexpected Configuration", "XMLConfigTest", config.getName());
  final LoggerConfig lcfg = config.getLoggerConfig("org.apache.logging.log4j.test1");
  assertNotNull("No Logger", lcfg);
  final Filter filter = lcfg.getFilter();
  assertNotNull("No Filter", filter);
  assertThat(filter, instanceOf(CompositeFilter.class));
  assertTrue("Unexpected filters", ((CompositeFilter) filter).isEmpty());
}

代码示例来源:origin: org.apache.logging.log4j/log4j-core

@Test
public void testEnvironment() throws Exception {
  ctx = Configurator.initialize("-config", null);
  LogManager.getLogger("org.apache.test.TestConfigurator");
  final Configuration config = ctx.getConfiguration();
  assertNotNull("No configuration", config);
  assertEquals("Incorrect Configuration.", CONFIG_NAME, config.getName());
  final Map<String, Appender> map = config.getAppenders();
  assertNotNull("Appenders map should not be null.", map);
  assertThat(map, hasSize(greaterThan(0)));
  assertThat("No ListAppender named List2", map, hasKey("List2"));
  final Appender app = map.get("List2");
  final Layout<? extends Serializable> layout = app.getLayout();
  assertNotNull("Appender List2 does not have a Layout", layout);
  assertThat("Appender List2 is not configured with a PatternLayout", layout, instanceOf(PatternLayout.class));
  final String pattern = ((PatternLayout) layout).getConversionPattern();
  assertNotNull("No conversion pattern for List2 PatternLayout", pattern);
  assertFalse("Environment variable was not substituted", pattern.startsWith("${env:PATH}"));
}

代码示例来源:origin: org.apache.logging.log4j/log4j-core

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);

代码示例来源:origin: org.apache.logging.log4j/log4j-core

@Test
public void testBuilder() throws Exception {
  final ConfigurationBuilder<BuiltConfiguration> builder = ConfigurationBuilderFactory.newConfigurationBuilder();
  builder.setStatusLevel(Level.ERROR);
  builder.setConfigurationName("BuilderTest");
  builder.add(builder.newFilter("ThresholdFilter", Filter.Result.ACCEPT, Filter.Result.NEUTRAL)
      .addAttribute("level", Level.DEBUG));
  final AppenderComponentBuilder appenderBuilder = builder.newAppender("Stdout", "CONSOLE").addAttribute("target",
      ConsoleAppender.Target.SYSTEM_OUT);
  appenderBuilder.add(builder.newLayout("PatternLayout").
      addAttribute("pattern", "%d [%t] %-5level: %msg%n%throwable"));
  appenderBuilder.add(builder.newFilter("MarkerFilter", Filter.Result.DENY,
      Filter.Result.NEUTRAL).addAttribute("marker", "FLOW"));
  builder.add(appenderBuilder);
  builder.add(builder.newLogger("org.apache.logging.log4j", Level.DEBUG).
      add(builder.newAppenderRef("Stdout")).
      addAttribute("additivity", false));
  builder.add(builder.newRootLogger(Level.ERROR).add(builder.newAppenderRef("Stdout")));
  ctx = Configurator.initialize(builder.build());
  final Configuration config = ctx.getConfiguration();
  assertNotNull("No configuration", config);
  assertEquals("Unexpected Configuration", "BuilderTest", config.getName());
  assertThat(config.getAppenders(), hasSize(equalTo(1)));
}

相关文章