Java 类org.apache.logging.log4j.core.config.ConfigurationFactory 实例源码

项目:JukeBot    文件:JukeBot.java   
public static void main(final String[] args) throws Exception {
    Thread.currentThread().setName("JukeBot-Main");

    ConfigurationFactory.setConfigurationFactory(new Log4JConfig());
    LOG = LogManager.getLogger("JukeBot");

    playerManager = new DefaultAudioPlayerManager();
    defaultPrefix = Database.getPropertyFromConfig("prefix");

    String colour = Database.getPropertyFromConfig("color");
    if (colour.equalsIgnoreCase("")) {
        LOG.error("Missing property 'color' in the database.");
        return;
    }

    embedColour = Color.decode(colour);

    playerManager.setPlayerCleanupThreshold(30000);
    playerManager.getConfiguration().setResamplingQuality(AudioConfiguration.ResamplingQuality.LOW);
    playerManager.getConfiguration().setOpusEncodingQuality(9);
    YoutubeAudioSourceManager yt = new YoutubeAudioSourceManager();
    yt.setPlaylistPageCount(Integer.MAX_VALUE);
    playerManager.registerSourceManager(yt);
    AudioSourceManagers.registerRemoteSources(playerManager);

    printBanner();

    shardManager = new DefaultShardManagerBuilder()
            .setToken(Database.getPropertyFromConfig("token"))
            .setShardsTotal(-1)
            .addEventListeners(new EventListener(), waiter)
            .setAudioSendFactory(new NativeAudioSendFactory())
            .setGame(Game.of(Game.GameType.LISTENING, defaultPrefix + "help | jukebot.xyz"))
            .build();
}
项目:monarch    文件:GfshInitFileJUnitTest.java   
@BeforeClass
public static void setUpBeforeClass() throws Exception {
  saveLog4j2Config = System.getProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
  saveUserDir = System.getProperty("user.dir");
  saveUserHome = System.getProperty("user.home");

  julLogger = java.util.logging.Logger.getLogger("");
  saveHandlers = julLogger.getHandlers();
  for (Handler handler : saveHandlers) {
    julLogger.removeHandler(handler);
  }

  File log4j2XML = temporaryFolder_Config.newFile("log4j2.xml");
  FileUtils.writeStringToFile(log4j2XML, "<Configuration/>", APPEND);
  System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY,
      log4j2XML.toURI().toString());
}
项目:monarch    文件:GfshInitFileJUnitTest.java   
@AfterClass
public static void tearDownAfterClass() throws Exception {
  for (Handler handler : saveHandlers) {
    julLogger.addHandler(handler);
  }

  if (saveLog4j2Config == null) {
    System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
  } else {
    System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, saveLog4j2Config);
    ((LoggerContext) LogManager.getContext(false)).reconfigure();
  }

  if (saveUserDir == null) {
    System.clearProperty("user.dir");
  } else {
    System.setProperty("user.dir", saveUserDir);
  }
  if (saveUserHome == null) {
    System.clearProperty("user.home");
  } else {
    System.setProperty("user.home", saveUserHome);
  }
}
项目:monarch    文件:GeodeVerboseLogMarkerIntegrationTest.java   
@After
public void tearDown() throws Exception {
  Configurator.shutdown();

  System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
  if (this.beforeConfigFileProp != null) {
    System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY,
        this.beforeConfigFileProp);
  }
  StatusLogger.getLogger().setLevel(this.beforeLevel);

  LogService.reconfigure();
  assertThat(LogService.isUsingGemFireDefaultConfig()).as(LogService.getConfigInformation())
      .isTrue();

  BasicAppender.clearInstance();

  assertThat(this.systemErrRule.getLog()).isEmpty();
}
项目:monarch    文件:CustomConfigWithLogServiceIntegrationTest.java   
@Before
public void setUp() throws Exception {
  Configurator.shutdown();
  BasicAppender.clearInstance();

  this.beforeConfigFileProp =
      System.getProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
  this.beforeLevel = StatusLogger.getLogger().getLevel();

  this.customConfigFile = createConfigFileIn(this.temporaryFolder.getRoot());

  System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY,
      this.customConfigFile.getAbsolutePath());
  LogService.reconfigure();
  assertThat(LogService.isUsingGemFireDefaultConfig()).as(LogService.getConfigInformation())
      .isFalse();
}
项目:monarch    文件:CustomConfigWithLogServiceIntegrationTest.java   
@After
public void tearDown() throws Exception {
  Configurator.shutdown();

  System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
  if (this.beforeConfigFileProp != null) {
    System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY,
        this.beforeConfigFileProp);
  }
  StatusLogger.getLogger().setLevel(this.beforeLevel);

  LogService.reconfigure();
  assertThat(LogService.isUsingGemFireDefaultConfig()).as(LogService.getConfigInformation())
      .isTrue();

  BasicAppender.clearInstance();

  assertThat(this.systemErrRule.getLog()).isEmpty();
}
项目:monarch    文件:CustomConfigWithCacheIntegrationTest.java   
@Before
public void setUp() throws Exception {
  Configurator.shutdown();
  BasicAppender.clearInstance();

  this.beforeConfigFileProp =
      System.getProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
  this.beforeLevel = StatusLogger.getLogger().getLevel();

  this.customConfigFile = createConfigFileIn(this.temporaryFolder.getRoot());

  System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY,
      this.customConfigFile.getAbsolutePath());

  Properties gemfireProperties = new Properties();
  gemfireProperties.put(LOCATORS, "");
  gemfireProperties.put(MCAST_PORT, "0");
  gemfireProperties.put(LOG_LEVEL, "info");
  this.cache = new CacheFactory(gemfireProperties).create();
}
项目:monarch    文件:CustomConfigWithCacheIntegrationTest.java   
@After
public void tearDown() throws Exception {
  if (this.cache != null) {
    this.cache.getDistributedSystem().disconnect();
  }

  Configurator.shutdown();

  System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
  if (this.beforeConfigFileProp != null) {
    System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY,
        this.beforeConfigFileProp);
  }
  StatusLogger.getLogger().setLevel(this.beforeLevel);

  LogService.reconfigure();
  assertThat(LogService.isUsingGemFireDefaultConfig()).as(LogService.getConfigInformation())
      .isTrue();

  BasicAppender.clearInstance();

  assertThat(this.systemErrRule.getLog()).isEmpty();
}
项目:QD    文件:Log4j2CompatibilityTest.java   
@Override
protected void setUp() throws Exception {
    super.setUp();

    initLogFormatter();
    System.getProperties().setProperty(Logging.LOG_CLASS_NAME, "com.devexperts.logging.Log4j2Logging");

    // Create log file in folder that will be eventually cleared - "deleteOnExit" does not work for log files.
    BUILD_TEST_DIR.mkdirs();
    logFile = File.createTempFile("test.", ".log", BUILD_TEST_DIR);
    final Properties props = new Properties();
    props.load(Log4jCompatibilityTest.class.getResourceAsStream("/test.log4j2.properties"));
    props.setProperty("appender.file.fileName", logFile.getPath());
    LoggerContext context = (LoggerContext)LogManager.getContext(false);
    ConfigurationFactory.setConfigurationFactory(new PropertiesConfigurationFactory() {
        @Override
        public PropertiesConfiguration getConfiguration(LoggerContext loggerContext, ConfigurationSource source) {
            return new PropertiesConfigurationBuilder()
                .setConfigurationSource(source)
                .setRootProperties(props)
                .setLoggerContext(loggerContext)
                .build();
        }
    });
    context.setConfigLocation(Log4jCompatibilityTest.class.getResource("/test.log4j2.properties").toURI());
}
项目:contestparser    文件:Log4J2LoggingSystem.java   
protected void loadConfiguration(String location, LogFile logFile) {
    Assert.notNull(location, "Location must not be null");
    if (logFile != null) {
        logFile.applyToSystemProperties();
    }
    try {
        LoggerContext ctx = getLoggerContext();
        URL url = ResourceUtils.getURL(location);
        ConfigurationSource source = getConfigurationSource(url);
        ctx.start(ConfigurationFactory.getInstance().getConfiguration(source));
    }
    catch (Exception ex) {
        throw new IllegalStateException(
                "Could not initialize Log4J2 logging from " + location, ex);
    }
}
项目:log4j    文件:TestSolrAppender.java   
@BeforeClass
public static void init() {
    try {
        // read log4j configuration from xml
        InputStream in = new FileInputStream(new File(TestSolrAppender.class.getResource("./log4j2.xml").getPath()));
        ConfigurationFactory factory = new XMLConfigurationFactory();
        Configuration configuration = factory
                .getConfiguration(new ConfigurationSource(in));

        // init context
        context = (LoggerContext) LogManager.getContext();
        context.start(configuration);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }   

}
项目:logging-log4j2    文件:FlumeEmbeddedAppenderTest.java   
@After
public void teardown() throws Exception {
    System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
    ctx.reconfigure();
    primary.stop();
    alternate.stop();
    final File file = new File("target/file-channel");
    deleteFiles(file);
    final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    final Set<ObjectName> names = server.queryNames(new ObjectName("org.apache.flume.*:*"), null);
    for (final ObjectName name : names) {
        try {
            server.unregisterMBean(name);
        } catch (final Exception ex) {
            System.out.println("Unable to unregister " + name.toString());
        }
    }
}
项目:logging-log4j2    文件:Log4jContextFactory.java   
/**
 * Loads the LoggerContext using the ContextSelector.
 * @param fqcn The fully qualified class name of the caller.
 * @param loader The ClassLoader to use or null.
 * @param externalContext An external context (such as a ServletContext) to be associated with the LoggerContext.
 * @param currentContext If true returns the current Context, if false returns the Context appropriate
 * for the caller if a more appropriate Context can be determined.
 * @param source The configuration source.
 * @return The LoggerContext.
 */
public LoggerContext getContext(final String fqcn, final ClassLoader loader, final Object externalContext,
                                final boolean currentContext, final ConfigurationSource source) {
    final LoggerContext ctx = selector.getContext(fqcn, loader, currentContext, null);
    if (externalContext != null && ctx.getExternalContext() == null) {
        ctx.setExternalContext(externalContext);
    }
    if (ctx.getState() == LifeCycle.State.INITIALIZED) {
        if (source != null) {
            ContextAnchor.THREAD_CONTEXT.set(ctx);
            final Configuration config = ConfigurationFactory.getInstance().getConfiguration(ctx, source);
            LOGGER.debug("Starting LoggerContext[name={}] from configuration {}", ctx.getName(), source);
            ctx.start(config);
            ContextAnchor.THREAD_CONTEXT.remove();
        } else {
            ctx.start();
        }
    }
    return ctx;
}
项目:log4j2    文件:FlumeEmbeddedAgentTest.java   
@After
public void teardown() throws Exception {
    System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
    ctx.reconfigure();
    primary.stop();
    alternate.stop();
    final File file = new File("target/file-channel");
    final boolean result = deleteFiles(file);
    final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    final Set<ObjectName> names = server.queryNames(new ObjectName("org.apache.flume.*:*"), null);
    for (final ObjectName name : names) {
        try {
            server.unregisterMBean(name);
        } catch (final Exception ex) {
            System.out.println("Unable to unregister " + name.toString());
        }
    }
}
项目:log4j2    文件:FlumePersistentPerf.java   
@Before
public void setUp() throws Exception {

    final File file = new File("target/persistent");
    final boolean result = deleteFiles(file);

    /*
    * Clear out all other appenders associated with this logger to ensure we're
    * only hitting the Avro appender.
    */
    final int[] ports = findFreePorts(2);
    System.setProperty("primaryPort", Integer.toString(ports[0]));
    System.setProperty("alternatePort", Integer.toString(ports[1]));
    primary = new EventCollector(ports[0]);
    alternate = new EventCollector(ports[1]);
    System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
    ctx = (LoggerContext) LogManager.getContext(false);
    ctx.reconfigure();
}
项目:logging-log4j2    文件:LoggerContextAdmin.java   
@Override
public void setConfigText(final String configText, final String charsetName) {
    LOGGER.debug("---------");
    LOGGER.debug("Remote request to reconfigure from config text.");

    try {
        final InputStream in = new ByteArrayInputStream(configText.getBytes(charsetName));
        final ConfigurationSource source = new ConfigurationSource(in);
        final Configuration updated = ConfigurationFactory.getInstance().getConfiguration(loggerContext, source);
        loggerContext.start(updated);
        LOGGER.debug("Completed remote request to reconfigure from config text.");
    } catch (final Exception ex) {
        final String msg = "Could not reconfigure from config text";
        LOGGER.error(msg, ex);
        throw new IllegalArgumentException(msg, ex);
    }
}
项目:log4j2    文件:FlumePersistentAppenderTest.java   
@Before
public void setUp() throws Exception {

    final File file = new File("target/persistent");
    final boolean result = deleteFiles(file);

    /*
    * Clear out all other appenders associated with this logger to ensure we're
    * only hitting the Avro appender.
    */
    final int[] ports = findFreePorts(2);
    System.setProperty("primaryPort", Integer.toString(ports[0]));
    System.setProperty("alternatePort", Integer.toString(ports[1]));
    primary = new EventCollector(ports[0]);
    alternate = new EventCollector(ports[1]);
    System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
    ctx = (LoggerContext) LogManager.getContext(false);
    ctx.reconfigure();
}
项目:log4j2    文件:FlumePersistentAppenderTest.java   
@After
public void teardown() throws Exception {
    System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
    ctx.reconfigure();
    primary.stop();
    alternate.stop();
    final File file = new File("target/file-channel");
    final boolean result = deleteFiles(file);
    final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    final Set<ObjectName> names = server.queryNames(new ObjectName("org.apache.flume.*:*"), null);
    for (final ObjectName name : names) {
        try {
            server.unregisterMBean(name);
        } catch (final Exception ex) {
            System.out.println("Unable to unregister " + name.toString());
        }
    }
}
项目:log4j2    文件:LoggerContextAdmin.java   
@Override
public void setConfigText(final String configText, final String charsetName) {
    final String old = customConfigText;
    customConfigText = Assert.isNotNull(configText, "configText");
    LOGGER.debug("---------");
    LOGGER.debug("Remote request to reconfigure from config text.");

    try {
        final InputStream in = new ByteArrayInputStream(
                configText.getBytes(charsetName));
        final ConfigurationSource source = new ConfigurationSource(in);
        final Configuration updated = ConfigurationFactory.getInstance()
                .getConfiguration(source);
        loggerContext.start(updated);
        LOGGER.debug("Completed remote request to reconfigure from config text.");
    } catch (final Exception ex) {
        customConfigText = old;
        final String msg = "Could not reconfigure from config text";
        LOGGER.error(msg, ex);
        throw new IllegalArgumentException(msg, ex);
    }
}
项目:logging-log4j2    文件:Log4jContextFactory.java   
/**
 * Loads the LoggerContext using the ContextSelector.
 * @param fqcn The fully qualified class name of the caller.
 * @param loader The ClassLoader to use or null.
 * @param externalContext An external context (such as a ServletContext) to be associated with the LoggerContext.
 * @param currentContext If true returns the current Context, if false returns the Context appropriate
 * for the caller if a more appropriate Context can be determined.
 * @param configLocation The location of the configuration for the LoggerContext (or null).
 * @return The LoggerContext.
 */
@Override
public LoggerContext getContext(final String fqcn, final ClassLoader loader, final Object externalContext,
                                final boolean currentContext, final URI configLocation, final String name) {
    final LoggerContext ctx = selector.getContext(fqcn, loader, currentContext, configLocation);
    if (externalContext != null && ctx.getExternalContext() == null) {
        ctx.setExternalContext(externalContext);
    }
    if (name != null) {
        ctx.setName(name);
    }
    if (ctx.getState() == LifeCycle.State.INITIALIZED) {
        if (configLocation != null || name != null) {
            ContextAnchor.THREAD_CONTEXT.set(ctx);
            final Configuration config = ConfigurationFactory.getInstance().getConfiguration(ctx, name, configLocation);
            LOGGER.debug("Starting LoggerContext[name={}] from configuration at {}", ctx.getName(), configLocation);
            ctx.start(config);
            ContextAnchor.THREAD_CONTEXT.remove();
        } else {
            ctx.start();
        }
    }
    return ctx;
}
项目:logging-log4j2    文件:LoggerContext.java   
/**
 * Reconfigures the context.
 */
private void reconfigure(final URI configURI) {
    final ClassLoader cl = ClassLoader.class.isInstance(externalContext) ? (ClassLoader) externalContext : null;
    LOGGER.debug("Reconfiguration started for context[name={}] at URI {} ({}) with optional ClassLoader: {}",
            contextName, configURI, this, cl);
    final Configuration instance = ConfigurationFactory.getInstance().getConfiguration(this, contextName, configURI, cl);
    if (instance == null) {
        LOGGER.error("Reconfiguration failed: No configuration found for '{}' at '{}' in '{}'", contextName, configURI, cl);
    } else {
        setConfiguration(instance);
        /*
         * instance.start(); Configuration old = setConfiguration(instance); updateLoggers(); if (old != null) {
         * old.stop(); }
         */
        final String location = configuration == null ? "?" : String.valueOf(configuration.getConfigurationSource());
        LOGGER.debug("Reconfiguration complete for context[name={}] at URI {} ({}) with optional ClassLoader: {}",
                contextName, location, this, cl);
    }
}
项目:logging-log4j2    文件:FlumePersistentPerf.java   
@Before
public void setUp() throws Exception {

    final File file = new File("target/persistent");
    deleteFiles(file);

    /*
    * Clear out all other appenders associated with this logger to ensure we're
    * only hitting the Avro appender.
    */
    final int primaryPort = AvailablePortFinder.getNextAvailable();
    final int altPort = AvailablePortFinder.getNextAvailable();
    System.setProperty("primaryPort", Integer.toString(primaryPort));
    System.setProperty("alternatePort", Integer.toString(altPort));
    primary = new EventCollector(primaryPort);
    alternate = new EventCollector(altPort);
    System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
    ctx = LoggerContext.getContext(false);
    ctx.reconfigure();
}
项目:logging-log4j2    文件:FlumePersistentAppenderTest.java   
@After
public void teardown() throws Exception {
    System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
    ctx.reconfigure();
    primary.stop();
    alternate.stop();
    final File file = new File("target/file-channel");
    deleteFiles(file);
    final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    final Set<ObjectName> names = server.queryNames(new ObjectName("org.apache.flume.*:*"), null);
    for (final ObjectName name : names) {
        try {
            server.unregisterMBean(name);
        } catch (final Exception ex) {
            System.out.println("Unable to unregister " + name.toString());
        }
    }
}
项目:logging-log4j2    文件:FlumeEmbeddedAgentTest.java   
@After
public void teardown() throws Exception {
    System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
    ctx.reconfigure();
    primary.stop();
    alternate.stop();
    final File file = new File("target/file-channel");
    deleteFiles(file);
    final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    final Set<ObjectName> names = server.queryNames(new ObjectName("org.apache.flume.*:*"), null);
    for (final ObjectName name : names) {
        try {
            server.unregisterMBean(name);
        } catch (final Exception ex) {
            System.out.println("Unable to unregister " + name.toString());
        }
    }
}
项目:log4j2-extended-jsonlayout    文件:ExtendedJsonLayoutTest.java   
@BeforeClass
public static void setupClass() {
    ThreadContext.clearAll();
    ConfigurationFactory.setConfigurationFactory(cf);
    final LoggerContext ctx = LoggerContext.getContext();
    ctx.reconfigure();
}
项目:logging-log4j-boot    文件:Log4jLoggingSystem.java   
private static String[] determineStandardConfigLocations() {
    final List<String> locations = new ArrayList<>();
    for (final ConfigurationFactory factory : findFactories()) {
        for (final String extension : getSupportedTypes(factory)) {
            if ("*".equals(extension)) {
                continue;
            }
            locations.add("log4j2-test" + extension);
            locations.add("log4j2" + extension);
        }
    }
    return locations.toArray(new String[0]);
}
项目:logging-log4j-boot    文件:Log4jLoggingSystem.java   
private static Collection<ConfigurationFactory> findFactories() {
    final PluginManager manager = new PluginManager(ConfigurationFactory.CATEGORY);
    manager.collectPlugins();
    final Collection<ConfigurationFactory> factories = new ArrayList<>();
    for (final PluginType<?> type : manager.getPlugins().values()) {
        final ConfigurationFactory factory = tryCreateFactory(type);
        if (factory != null) {
            factories.add(factory);
        }
    }
    return factories;
}
项目:logging-log4j-boot    文件:Log4jLoggingSystem.java   
private static ConfigurationFactory tryCreateFactory(final PluginType<?> pluginType) {
    try {
        return pluginType.getPluginClass().asSubclass(ConfigurationFactory.class).newInstance();
    } catch (final Exception ignored) {
        return null;
    }
}
项目:logging-log4j-boot    文件:Log4jLoggingSystem.java   
private static String[] getSupportedTypes(final ConfigurationFactory factory) {
    try {
        if ((boolean) FACTORY_IS_ACTIVE.invoke(factory)) {
            return (String[]) FACTORY_SUPPORTED_TYPES.invoke(factory);
        }
    } catch (final Exception ignored) {
    }
    return new String[0];
}
项目:monarch    文件:LogWriterLoggerPerformanceTest.java   
protected Logger createLogger() throws IOException {
  // create configuration with log-file and log-level
  this.configDirectory = new File(getUniqueName());
  this.configDirectory.mkdir();
  assertTrue(this.configDirectory.isDirectory() && this.configDirectory.canWrite());

  // copy the log4j2-test.xml to the configDirectory
  // final URL srcURL =
  // getClass().getResource("/org/apache/geode/internal/logging/log4j/log4j2-test.xml");
  final URL srcURL = getClass().getResource("log4j2-test.xml");
  final File src = new File(srcURL.getFile());
  FileUtils.copyFileToDirectory(src, this.configDirectory);
  this.config = new File(this.configDirectory, "log4j2-test.xml");
  assertTrue(this.config.exists());

  this.logFile = new File(this.configDirectory, DistributionConfig.GEMFIRE_PREFIX + "log");
  final String logFilePath = IOUtils.tryGetCanonicalPathElseGetAbsolutePath(logFile);
  final String logFileName = FileUtil.stripOffExtension(logFilePath);
  setPropertySubstitutionValues(logFileName, DEFAULT_LOG_FILE_SIZE_LIMIT,
      DEFAULT_LOG_FILE_COUNT_LIMIT);

  final String configPath =
      "file://" + IOUtils.tryGetCanonicalPathElseGetAbsolutePath(this.config);
  System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, configPath);

  final Logger logger = LogWriterLogger.create(this.getClass().getName(), false);
  return logger;
}
项目:monarch    文件:GeodeVerboseLogMarkerIntegrationTest.java   
@Before
public void setUp() throws Exception {
  Configurator.shutdown();
  BasicAppender.clearInstance();

  this.beforeConfigFileProp =
      System.getProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
  this.beforeLevel = StatusLogger.getLogger().getLevel();

  this.configFileGemfireVerboseAccept = createConfigFile(FILE_NAME_GEMFIRE_VERBOSE_ACCEPT);
  this.configFileGemfireVerboseDeny = createConfigFile(FILE_NAME_GEMFIRE_VERBOSE_DENY);
  this.configFileGeodeVerboseAccept = createConfigFile(FILE_NAME_GEODE_VERBOSE_ACCEPT);
  this.configFileGeodeVerboseDeny = createConfigFile(FILE_NAME_GEODE_VERBOSE_DENY);
}
项目:monarch    文件:FastLoggerIntegrationJUnitTest.java   
@Before
public void setUp() throws Exception {
  System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
  this.configFile = new File(this.temporaryFolder.getRoot(), "log4j2-test.xml");
  this.configFileLocation = this.configFile.toURI().toURL().toString();
  this.enabledMarker = MarkerManager.getMarker(ENABLED_MARKER_NAME);
  this.unusedMarker = MarkerManager.getMarker(UNUSED_MARKER_NAME);
  setUpLogService();
}
项目:monarch    文件:FastLoggerIntegrationJUnitTest.java   
private void setUpLogService() throws Exception {
  // Load a base config and do some sanity checks
  writeSimpleConfigFile(this.configFile, Level.WARN);
  System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, this.configFileLocation);

  LogService.reconfigure();
  LogService.getLogger().getName(); // This causes the config file to be loaded
  this.logger = LogService.getLogger(TEST_LOGGER_NAME);
  this.appenderContext =
      ((org.apache.logging.log4j.core.Logger) LogService.getRootLogger()).getContext();

  assertThat(LogService.getLogger(LogService.BASE_LOGGER_NAME).getLevel(), is(Level.FATAL));
  assertThat(this.logger, is(instanceOf(FastLogger.class)));
  assertThat(this.logger.getLevel(), is(Level.WARN));
}
项目:monarch    文件:Log4J2PerformanceTest.java   
protected Logger createLogger() throws IOException {
  // create configuration with log-file and log-level
  this.configDirectory = new File(getUniqueName());
  this.configDirectory.mkdir();
  assertTrue(this.configDirectory.isDirectory() && this.configDirectory.canWrite());

  // copy the log4j2-test.xml to the configDirectory
  // final URL srcURL =
  // getClass().getResource("/org/apache/geode/internal/logging/log4j/log4j2-test.xml");
  final URL srcURL = getClass().getResource("log4j2-test.xml");
  final File src = new File(srcURL.getFile());
  FileUtils.copyFileToDirectory(src, this.configDirectory);
  this.config = new File(this.configDirectory, "log4j2-test.xml");
  assertTrue(this.config.exists());

  this.logFile = new File(this.configDirectory, DistributionConfig.GEMFIRE_PREFIX + "log");
  final String logFilePath = IOUtils.tryGetCanonicalPathElseGetAbsolutePath(logFile);
  final String logFileName = FileUtil.stripOffExtension(logFilePath);
  setPropertySubstitutionValues(logFileName, DEFAULT_LOG_FILE_SIZE_LIMIT,
      DEFAULT_LOG_FILE_COUNT_LIMIT);

  final String configPath =
      "file://" + IOUtils.tryGetCanonicalPathElseGetAbsolutePath(this.config);
  System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, configPath);

  final Logger logger = LogManager.getLogger();
  return logger;
}
项目:monarch    文件:LogServiceIntegrationJUnitTest.java   
@Override
protected void before() {
  beforeConfigFileProp = System.getProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
  beforeLevel = StatusLogger.getLogger().getLevel();

  System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
  StatusLogger.getLogger().setLevel(Level.OFF);

  Configurator.shutdown();
}
项目:monarch    文件:LogServiceIntegrationJUnitTest.java   
@Override
protected void after() {
  Configurator.shutdown();

  System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
  if (beforeConfigFileProp != null) {
    System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, beforeConfigFileProp);
  }
  StatusLogger.getLogger().setLevel(beforeLevel);

  LogService.reconfigure();
  assertThat(LogService.isUsingGemFireDefaultConfig()).as(LogService.getConfigInformation())
      .isTrue();
}
项目:monarch    文件:LogServiceIntegrationJUnitTest.java   
@Test
public void shouldPreferConfigurationFilePropertyIfSet() throws Exception {
  final File configFile = this.temporaryFolder.newFile(DEFAULT_CONFIG_FILE_NAME);
  final String configFileName = configFile.toURI().toString();
  System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, configFileName);
  writeConfigFile(configFile, Level.DEBUG);

  LogService.reconfigure();

  assertThat(LogService.isUsingGemFireDefaultConfig()).as(LogService.getConfigInformation())
      .isFalse();
  assertThat(System.getProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY))
      .isEqualTo(configFileName);
  assertThat(LogService.getLogger().getName()).isEqualTo(getClass().getName());
}
项目:monarch    文件:LogServiceIntegrationJUnitTest.java   
@Test
public void shouldUseDefaultConfigIfNotConfigured() throws Exception {
  LogService.reconfigure();

  assertThat(LogService.isUsingGemFireDefaultConfig()).as(LogService.getConfigInformation())
      .isTrue();
  assertThat(System.getProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY))
      .isNullOrEmpty();
}
项目:monarch    文件:LogServiceIntegrationJUnitTest.java   
@Test
public void shouldNotUseDefaultConfigIfCliConfigSpecified() throws Exception {
  System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY,
      this.cliConfigUrl.toString());

  LogService.reconfigure();

  assertThat(LogService.isUsingGemFireDefaultConfig()).as(LogService.getConfigInformation())
      .isFalse();
  assertThat(System.getProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY))
      .isEqualTo(this.cliConfigUrl.toString());
  assertThat(LogService.getLogger().getName()).isEqualTo(getClass().getName());
}
项目:monarch    文件:LogServiceIntegrationJUnitTest.java   
@Test
public void isUsingGemFireDefaultConfigShouldBeTrueIfDefaultConfig() throws Exception {
  System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY,
      this.defaultConfigUrl.toString());

  assertThat(LogService.getConfiguration().getConfigurationSource().toString())
      .contains(DEFAULT_CONFIG_FILE_NAME);
  assertThat(LogService.isUsingGemFireDefaultConfig()).isTrue();
}