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


Java LoggerContext.getContext方法代码示例

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


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

示例1: start

import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的package包/类
@Setup
public void start() {
    counter = 0;
    if (log == null) {
        System.setProperty(
                "Log4jContextSelector",
                "org.apache.logging.log4j.core.async.AsyncLoggerContextSelector");
        LoggerContext context = LoggerContext.getContext();
        log = context.getLogger("Log4j2");
        log.setAdditive(false);
        ArrayList<Appender> list = new ArrayList<Appender>();
        list.addAll(log.getAppenders().values());
        for (Appender a : list) {
            log.removeAppender(a);
        }
    }
}
 
开发者ID:a-hansen,项目名称:alog,代码行数:18,代码来源:AlogBenchmark.java

示例2: testLogReconfiguration

import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的package包/类
/**
 * This test asserts that after re-configuration of the log engine the total appenders are
 * different. The 'comparison' will be done between:
 *
 * - default config (src/main/resources/log4j2.xml)
 * - alternative config (src/test/resources/xml/config-for-LogManagerTest.xml)
 */
@Test (groups = { GROUP_CHANGE_CONFIG }, description = "Validate the numbers of Appenders associated with the LoggerContext")
public void testLogReconfiguration() {
    LOGGER.debug("About to test re-configuration of the logger context");
    final String pathToAlternativeLogConfig = "src/test/resources/config/log/config-for-LogManagerTest.xml";
    LoggerContext loggerContext = LoggerContext.getContext(false);
    Configuration configuration = loggerContext.getConfiguration();
    Map<String, Appender> appenderMap = configuration.getAppenders();
    Assert.assertTrue(appenderMap.size() == 1, "Expected 1 appender");
    Assert.assertTrue(appenderMap.containsKey("console"));

    LogManager.initializeLogging(pathToAlternativeLogConfig);
    // Refresh reference of configuration as it changed
    configuration = loggerContext.getConfiguration();
    appenderMap = configuration.getAppenders();
    Assert.assertTrue(appenderMap.size() == 2, "Expected 2 appenders");
    Assert.assertTrue(appenderMap.containsKey("console"));
    Assert.assertTrue(appenderMap.containsKey("filterAppender"));
}
 
开发者ID:Technolords,项目名称:microservice-mock,代码行数:26,代码来源:LogManagerTest.java

示例3: updateLoggingSeverity

import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的package包/类
public void updateLoggingSeverity(@Observes @ConfigurationUpdate AppConfiguration appConfiguration) {
    String loggingLevel = appConfiguration.getLoggingLevel();
    if (StringHelper.isEmpty(loggingLevel)) {
        return;
    }

    log.info("Setting loggers level to: '{}'", loggingLevel);

    LoggerContext loggerContext = LoggerContext.getContext(false);

    if (StringHelper.equalsIgnoreCase("DEFAULT", loggingLevel)) {
        log.info("Reloadming log4j configuration");
        loggerContext.reconfigure();
        return;
    }

    Level level = Level.toLevel(loggingLevel, Level.INFO);

    for (org.apache.logging.log4j.core.Logger logger : loggerContext.getLoggers()) {
        String loggerName = logger.getName();
        if (loggerName.startsWith("org.xdi.service") || loggerName.startsWith("org.xdi.oxauth") || loggerName.startsWith("org.gluu")) {
            logger.setLevel(level);
        }
    }
}
 
开发者ID:GluuFederation,项目名称:oxTrust,代码行数:26,代码来源:AppInitializer.java

示例4: setExternalLoggerConfig

import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的package包/类
private boolean setExternalLoggerConfig() {
    log.info("External log configuration: " + appConfiguration.getExternalLoggerConfiguration());
    if (StringUtils.isEmpty(appConfiguration.getExternalLoggerConfiguration())) {
        return false;
    }
    File log4jFile = new File(appConfiguration.getExternalLoggerConfiguration());
    if (!log4jFile.exists()) {
        log.info("External log configuration does not exist.");
        return false;
    }
    LoggerContext loggerContext = LoggerContext.getContext(false);
    loggerContext.setConfigLocation(log4jFile.toURI());
    loggerContext.reconfigure();

    configurationUpdateEvent.select(ConfigurationUpdate.Literal.INSTANCE).fire(this.appConfiguration);
    return true;
}
 
开发者ID:GluuFederation,项目名称:oxAuth,代码行数:18,代码来源:LoggerService.java

示例5: updateLoggingSeverity

import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的package包/类
public void updateLoggingSeverity(@Observes @ConfigurationUpdate AppConfiguration appConfiguration) {
	String loggingLevel = appConfiguration.getLoggingLevel();
	if (StringHelper.isEmpty(loggingLevel)) {
		return;
	}

	log.info("Setting loggers level to: '{}'", loggingLevel);
	
	LoggerContext loggerContext = LoggerContext.getContext(false);

	if (StringHelper.equalsIgnoreCase("DEFAULT", loggingLevel)) {
		log.info("Reloading log4j configuration");
		loggerContext.reconfigure();
		return;
	}

	Level level = Level.toLevel(loggingLevel, Level.INFO);

	for (org.apache.logging.log4j.core.Logger logger : loggerContext.getLoggers()) {
		String loggerName = logger.getName();
		if (loggerName.startsWith("org.xdi.service") || loggerName.startsWith("org.xdi.oxauth") || loggerName.startsWith("org.gluu") || level == Level.OFF) {
			logger.setLevel(level);
		}
	}
}
 
开发者ID:GluuFederation,项目名称:oxAuth,代码行数:26,代码来源:AppInitializer.java

示例6: setup

import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的package包/类
@Setup
public void setup() throws Exception {
    connectionHSQLDB = getConnectionHSQLDB();
    connectionH2 = getConnectionH2();
    createTable(connectionHSQLDB, toCreateTableSqlStringHQLDB("fmLogEntry"));
    createTable(connectionH2, toCreateTableSqlStringH2("fmLogEntry"));

    System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, "log4j2-jdbc-appender.xml");
    final LoggerContext context = LoggerContext.getContext(false);
    if (context.getConfiguration() instanceof DefaultConfiguration) {
        context.reconfigure();
    }
    StatusLogger.getLogger().reset();
    loggerH2 = LogManager.getLogger("H2Logger");
    loggerHSQLDB = LogManager.getLogger("HSQLDBLogger");
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:17,代码来源:JdbcAppenderBenchmark.java

示例7: setUp

import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {

    final File file = new File("target/file-channel");
    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();
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:21,代码来源:FlumeEmbeddedAgentTest.java

示例8: setUp

import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的package包/类
@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();
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:21,代码来源:FlumePersistentPerf.java

示例9: setAllLevels

import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的package包/类
/**
 * Sets the levels of <code>parentLogger</code> and all 'child' loggers to the given <code>level</code>.
 * @param parentLogger the parent logger
 * @param level the new level
 */
public static void setAllLevels(final String parentLogger, final Level level) {
    // 1) get logger config
    // 2) if exact match, use it, if not, create it.
    // 3) set level on logger config
    // 4) update child logger configs with level
    // 5) update loggers
    final LoggerContext loggerContext = LoggerContext.getContext(false);
    final Configuration config = loggerContext.getConfiguration();
    boolean set = setLevel(parentLogger, level, config);
    for (final Map.Entry<String, LoggerConfig> entry : config.getLoggers().entrySet()) {
        if (entry.getKey().startsWith(parentLogger)) {
            set |= setLevel(entry.getValue(), level);
        }
    }
    if (set) {
        loggerContext.updateLoggers();
    }
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:24,代码来源:Configurator.java

示例10: testAccessManagerWithStrings

import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的package包/类
/**
 * Not a real test, just make sure we can compile access to the typed manager.
 *
 * @throws IOException
 */
@Test
public void testAccessManagerWithStrings() throws IOException {
    try (final LoggerContext ctx = LoggerContext.getContext(false)) {
        final Configuration config = ctx.getConfiguration();
        final File file = File.createTempFile("RollingFileAppenderAccessTest", ".tmp");
        file.deleteOnExit();
        final RollingFileAppender appender = RollingFileAppender.createAppender(file.getCanonicalPath(),
                "FilePattern", null, "Name", null, null, null, OnStartupTriggeringPolicy.createPolicy(1), null,
                null, null, null, null, null, config);
        final RollingFileManager manager = appender.getManager();
        // Since the RolloverStrategy and TriggeringPolicy are immutable, we could also use generics to type their
        // access.
        Assert.assertNotNull(manager.getRolloverStrategy());
        Assert.assertNotNull(manager.getTriggeringPolicy());
    }
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:22,代码来源:RollingFileAppenderAccessTest.java

示例11: testReplacement

import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的package包/类
@Test
public void testReplacement() {
    final LogEvent event = Log4jLogEvent.newBuilder() //
            .setLoggerName(EncodingPatternConverterTest.class.getName()) //
            .setLevel(Level.DEBUG) //
            .setMessage(new SimpleMessage("Test \r\n<div class=\"test\">this</div> & <div class='test'>that</div>"))
            .build();
    final StringBuilder sb = new StringBuilder();
    final LoggerContext ctx = LoggerContext.getContext();
    final String[] options = new String[]{"%msg"};
    final EncodingPatternConverter converter = EncodingPatternConverter
        .newInstance(ctx.getConfiguration(), options);
    assertNotNull("Error creating converter", converter);
    converter.format(event, sb);
    assertEquals(
        "Test \\r\\n&lt;div class=&quot;test&quot;&gt;this&lt;&#x2F;div&gt; &amp; &lt;div class=&apos;test&apos;&gt;that&lt;&#x2F;div&gt;",
        sb.toString());
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:19,代码来源:EncodingPatternConverterTest.java

示例12: testCrlfEscaping

import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的package包/类
@Test
public void testCrlfEscaping() {
    final LogEvent event = Log4jLogEvent.newBuilder() //
            .setLoggerName(EncodingPatternConverterTest.class.getName()) //
            .setLevel(Level.DEBUG) //
            .setMessage(new SimpleMessage("Test \r\n<div class=\"test\">this\r</div> & \n<div class='test'>that</div>"))
            .build();
    final StringBuilder sb = new StringBuilder();
    final LoggerContext ctx = LoggerContext.getContext();
    final String[] options = new String[]{"%msg", "CRLF"};
    final EncodingPatternConverter converter = EncodingPatternConverter
        .newInstance(ctx.getConfiguration(), options);
    assertNotNull("Error creating converter", converter);
    converter.format(event, sb);
    assertEquals(
        "Test \\r\\n<div class=\"test\">this\\r</div> & \\n<div class='test'>that</div>",
        sb.toString());
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:19,代码来源:EncodingPatternConverterTest.java

示例13: main

import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的package包/类
public static void main(String [] args){
	try{
		System.out.println(logger1.isDebugEnabled());
		System.out.println(logger1.isErrorEnabled());
		System.out.println(logger1.isInfoEnabled());

		System.out.println(logger2.isDebugEnabled());
		System.out.println(logger2.isErrorEnabled());
		System.out.println(logger2.isInfoEnabled());

		System.out.println(logger3.isDebugEnabled());
		System.out.println(logger3.isErrorEnabled());
		System.out.println(logger3.isInfoEnabled());

		System.out.println(logger4.isDebugEnabled());
		System.out.println(logger4.isErrorEnabled());
		System.out.println(logger4.isInfoEnabled());

		org.apache.logging.log4j.spi.LoggerContext context=LogManager.getContext();
		Logger logger = (Logger) LogManager.getLogger();
		LoggerConfig config=logger.get();
		Map<Property, Boolean> properties=config.getProperties();
		System.out.println(config.getName());
		LoggerContext ctx=LoggerContext.getContext();
		Object appenders=ctx.getConfiguration().getAppenders();
		System.out.println(appenders.toString());
	}catch(Exception e){
		e.printStackTrace();
	}finally{
		System.exit(0);
	}


}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:35,代码来源:TestLog4j2.java

示例14: setupClass

import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的package包/类
@BeforeClass
public static void setupClass() {
    ThreadContext.clearAll();
    ConfigurationFactory.setConfigurationFactory(cf);
    final LoggerContext ctx = LoggerContext.getContext();
    ctx.reconfigure();
}
 
开发者ID:savantly-net,项目名称:log4j2-extended-jsonlayout,代码行数:8,代码来源:ExtendedJsonLayoutTest.java

示例15: addFollowConsoleAppender

import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的package包/类
private void addFollowConsoleAppender() {
    final LoggerContext context = LoggerContext.getContext(false);
    final Configuration config = context.getConfiguration();
    final PatternLayout layout = PatternLayout.newBuilder().withPattern("%-5level %c{-4} - %msg%n").build();
    Appender appender = ConsoleAppender.newBuilder().setFollow(true).setTarget(ConsoleAppender.Target.SYSTEM_OUT)
            .withName("ExecutionRecorder").withLayout(layout).build();
    appender.start();
    config.addAppender(appender);
    config.getRootLogger().addAppender(appender, logLevel, null);
}
 
开发者ID:RUB-NDS,项目名称:TLS-Attacker,代码行数:11,代码来源:ExecutionRecorder.java


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