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


Java ThreadContext.clear方法代码示例

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


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

示例1: LoggingApp

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
public LoggingApp(final String member) {

        ThreadContext.clear();

        RequestContext.setSessionId("session1234");
        RequestContext.setIpAddress("127.0.0.1");
        RequestContext.setClientId("02121");
        RequestContext.setProductName("IB");
        RequestContext.setProductVersion("4.18.1");
        RequestContext.setLocale("en_US");
        RequestContext.setRegion("prod");

        if (events == null) {
            events = MockEventsSupplier.getAllEvents(member);
        }
    }
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:17,代码来源:LoggingApp.java

示例2: testEvents

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@Test
public void testEvents() {
    ThreadContext.put("loginId", "JohnDoe");
    ThreadContext.put("ipAddress", "192.168.0.120");
    ThreadContext.put("locale", Locale.US.getDisplayName());
    final TransferMessage msg = new TransferMessage();
    msg.put("ToAccount", "123456");
    msg.put("FromAccount", "123457");
    msg.put("Amount", "200.00");
    EventLogger.logEvent(msg);
    msg.setCompletionStatus("Transfer Complete");
    EventLogger.logEvent(msg);
    ThreadContext.clear();


}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:17,代码来源:XMLEvents.java

示例3: testLookup

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@Test
public void testLookup() {
    final Map<String, String> map = new HashMap<String, String>();
    map.put(TESTKEY, TESTVAL);
    final StrLookup lookup = new Interpolator(new MapLookup(map));
    ThreadContext.put(TESTKEY, TESTVAL);
    String value = lookup.lookup(TESTKEY);
    assertEquals(TESTVAL, value);
    value = lookup.lookup("ctx:" + TESTKEY);
    assertEquals(TESTVAL, value);
    value = lookup.lookup("sys:" + TESTKEY);
    assertEquals(TESTVAL, value);
    value = lookup.lookup("BadKey");
    assertNull(value);
    ThreadContext.clear();
    value = lookup.lookup("ctx:" + TESTKEY);
    assertEquals(TESTVAL, value);
    value = lookup.lookup("jndi:" + TEST_CONTEXT_RESOURCE_NAME);
    assertEquals(TEST_CONTEXT_NAME, value);
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:21,代码来源:InterpolatorTest.java

示例4: setContextMap

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked") // nothing we can do about this, restricted by SLF4J API
public void setContextMap(@SuppressWarnings("rawtypes") final Map map) {
    ThreadContext.clear();
    for (final Map.Entry<String, String> entry : ((Map<String, String>) map).entrySet()) {
        ThreadContext.put(entry.getKey(), entry.getValue());
    }
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:9,代码来源:Log4jMDCAdapter.java

示例5: mdc

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@Test
public void mdc() {
    ThreadContext.put("TestYear", new Integer(2010).toString());
    logger.debug("Debug message");
    ThreadContext.clear();
    logger.debug("Debug message");
    assertTrue("Incorrect number of events. Expected 2, actual " + list.strList.size(), list.strList.size() == 2);
    assertTrue("Incorrect year", list.strList.get(0).startsWith("2010"));
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:10,代码来源:LoggerTest.java

示例6: cleanupClass

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@AfterClass
public static void cleanupClass() {
    System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
    ctx.reconfigure();
    StatusLogger.getLogger().reset();
    ThreadContext.clear();
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:8,代码来源:StyleConverterTest.java

示例7: mdc

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@Test
public void mdc() {

    ThreadContext.put("TestYear", "2010");
    logger.debug("Debug message");
    ThreadContext.clear();
    logger.debug("Debug message");
    final List<LogEvent> events = app.getEvents();
    assertTrue("Incorrect number of events. Expected 2, actual " + events.size(), events.size() == 2);
    app.clear();
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:12,代码来源:StrictXMLConfigTest.java

示例8: structuredData

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@Test
public void structuredData() {
    ThreadContext.put("loginId", "JohnDoe");
    ThreadContext.put("ipAddress", "192.168.0.120");
    ThreadContext.put("locale", Locale.US.getDisplayName());
    final StructuredDataMessage msg = new StructuredDataMessage("[email protected]", "Transfer Complete", "Transfer");
    msg.put("ToAccount", "123456");
    msg.put("FromAccount", "123457");
    msg.put("Amount", "200.00");
    logger.info(MarkerManager.getMarker("EVENT"), msg);
    ThreadContext.clear();
    final List<LogEvent> events = app.getEvents();
    assertTrue("Incorrect number of events. Expected 1, actual " + events.size(), events.size() == 1);
    app.clear();
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:16,代码来源:StrictXMLConfigTest.java

示例9: before

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@Before
public void before() {
    config = ctx.getConfiguration();
    for (final Map.Entry<String, Appender> entry : config.getAppenders().entrySet()) {
        if (entry.getKey().equals("List")) {
            app = (ListAppender) entry.getValue();
            break;
        }
    }
    assertNotNull("No Appender", app);
    app.clear();
    ThreadContext.clear();
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:14,代码来源:JMSQueueFailoverTest.java

示例10: testFilter

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@Test
public void testFilter() {
    ThreadContext.put("userid", "testuser");
    ThreadContext.put("organization", "Apache");
    final KeyValuePair[] pairs = new KeyValuePair[] { new KeyValuePair("userid", "JohnDoe"),
                                                new KeyValuePair("organization", "Apache")};
    ThreadContextMapFilter filter = ThreadContextMapFilter.createFilter(pairs, "and", null, null);
    filter.start();
    assertTrue(filter.isStarted());
    assertTrue(filter.filter(null, Level.DEBUG, null, null, (Throwable)null) == Filter.Result.DENY);
    ThreadContext.remove("userid");
    assertTrue(filter.filter(null, Level.DEBUG, null, null, (Throwable)null) == Filter.Result.DENY);
    ThreadContext.put("userid", "JohnDoe");
    assertTrue(filter.filter(null, Level.ERROR, null, null, (Throwable)null) == Filter.Result.NEUTRAL);
    ThreadContext.put("organization", "ASF");
    assertTrue(filter.filter(null, Level.DEBUG, null, null, (Throwable)null) == Filter.Result.DENY);
    ThreadContext.clear();
    filter = ThreadContextMapFilter.createFilter(pairs, "or", null, null);
    filter.start();
    assertTrue(filter.isStarted());
    ThreadContext.put("userid", "testuser");
    ThreadContext.put("organization", "Apache");
    assertTrue(filter.filter(null, Level.DEBUG, null, null, (Throwable)null) == Filter.Result.NEUTRAL);
    ThreadContext.put("organization", "ASF");
    assertTrue(filter.filter(null, Level.DEBUG, null, null, (Throwable)null) == Filter.Result.DENY);
    ThreadContext.remove("organization");
    assertTrue(filter.filter(null, Level.DEBUG, null, null, (Throwable)null) == Filter.Result.DENY);
    final KeyValuePair[] single = new KeyValuePair[] {new KeyValuePair("userid", "testuser")};
    filter = ThreadContextMapFilter.createFilter(single, null, null, null);
    filter.start();
    assertTrue(filter.isStarted());
    assertTrue(filter.filter(null, Level.DEBUG, null, null, (Throwable)null) == Filter.Result.NEUTRAL);
    ThreadContext.clear();
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:35,代码来源:ThreadContextMapFilterTest.java

示例11: mdc

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@Test
public void mdc() {
    ThreadContext.put("TestYear", "2010");
    logger.debug("Debug message");
    ThreadContext.clear();
    logger.debug("Debug message");
    final List<LogEvent> events = app.getEvents();
    assertTrue("Incorrect number of events. Expected 2, actual " + events.size(), events.size() == 2);
    app.clear();
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:11,代码来源:LoggerTest.java

示例12: clear

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
public static void clear() {
    localMap.get().clear();
    ThreadContext.clear();
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:5,代码来源:MDC.java

示例13: clear

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@Override
public void clear() {
    ThreadContext.clear();
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:5,代码来源:Log4jMDCAdapter.java

示例14: initialize

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
public static void initialize() {
    ThreadContext.clear();
    ThreadContext.put(REQUEST_ID, UUIDUtil.getTimeBasedUUID().toString());
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:5,代码来源:RequestContext.java


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