本文整理了Java中org.apache.logging.log4j.ThreadContext.clearMap()
方法的一些代码示例,展示了ThreadContext.clearMap()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ThreadContext.clearMap()
方法的具体详情如下:
包路径:org.apache.logging.log4j.ThreadContext
类名称:ThreadContext
方法名:clearMap
[英]Clears the context map.
[中]清除上下文映射。
代码示例来源:origin: org.apache.logging.log4j/log4j-api
/**
* Clears the context map and stack.
*/
public static void clearAll() {
clearMap();
clearStack();
}
代码示例来源:origin: org.apache.logging.log4j/log4j-slf4j-impl
@Override
@SuppressWarnings("unchecked") // nothing we can do about this, restricted by SLF4J API
public void setContextMap(@SuppressWarnings("rawtypes") final Map map) {
ThreadContext.clearMap();
for (final Map.Entry<String, String> entry : ((Map<String, String>) map).entrySet()) {
ThreadContext.put(entry.getKey(), entry.getValue());
}
}
}
代码示例来源:origin: org.apache.logging.log4j/log4j-api
@Override
public void run() {
final String greeting = ThreadContext.get("Greeting");
if (greeting == null) {
sb.append("null");
} else {
sb.append(greeting);
}
ThreadContext.clearMap();
}
}
代码示例来源:origin: org.apache.logging.log4j/log4j-api
@Override
public void run() {
final String greeting = ThreadContext.get("Greeting");
if (greeting == null) {
sb.append("null");
} else {
sb.append(greeting);
}
ThreadContext.clearMap();
}
}
代码示例来源:origin: org.apache.logging.log4j/log4j-api
public static void testGetImmutableContextReturnsImmutableMapIfEmpty() {
ThreadContext.clearMap();
final Map<String, String> immutable = ThreadContext.getImmutableContext();
immutable.put("otherkey", "otherval");
}
代码示例来源:origin: org.apache.logging.log4j/log4j-api
public static void testGetImmutableContextReturnsImmutableMapIfNonEmpty() {
ThreadContext.clearMap();
ThreadContext.put("key", "val");
final Map<String, String> immutable = ThreadContext.getImmutableContext();
immutable.put("otherkey", "otherval");
}
代码示例来源:origin: org.apache.logging.log4j/log4j-api
public static void testGetImmutableContextReturnsEmptyMapIfEmpty() {
ThreadContext.clearMap();
assertTrue(ThreadContext.getImmutableContext().isEmpty());
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
@Test
public void mdc() {
ThreadContext.put("TestYear", "2010");
logger.debug("Debug message");
ThreadContext.clearMap();
logger.debug("Debug message");
final List<LogEvent> events = app.getEvents();
assertEquals("Incorrect number of events. Expected 2, actual " + events.size(), 2, events.size());
}
代码示例来源:origin: org.apache.logging.log4j/log4j-api
@Override
protected void before() throws Throwable {
threadContextHolder = new ThreadContextHolder(restoreMap, restoreStack);
if (restoreMap) {
ThreadContext.clearMap();
}
if (restoreStack) {
ThreadContext.clearStack();
}
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
@Test
public void mdc() {
ThreadContext.put("TestYear", "2010");
logger.debug("Debug message");
ThreadContext.clearMap();
logger.debug("Debug message");
final List<LogEvent> events = app.getEvents();
assertEventCount(events, 2);
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
@Test
public void testGroovyFilter() throws Exception {
final Logger logger = LogManager.getLogger("TestGroovyFilter");
logger.traceEntry();
logger.info("This should not be logged");
ThreadContext.put("UserId", "JohnDoe");
logger.info("This should be logged");
ThreadContext.clearMap();
final ListAppender app = getContext().getListAppender("List");
try {
final List<String> messages = app.getMessages();
assertNotNull("No Messages", messages);
assertTrue("Incorrect number of messages. Expected 2, Actual " + messages.size(), messages.size() == 2);
} finally {
app.clear();
}
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
@Test
public void testConverterFullEmpty() {
ThreadContext.clearMap();
final Message msg = new SimpleMessage("Hello");
final MdcPatternConverter converter = MdcPatternConverter.newInstance(null);
final LogEvent event = Log4jLogEvent.newBuilder() //
.setLoggerName("MyLogger") //
.setLevel(Level.DEBUG) //
.setMessage(msg) //
.build();
final StringBuilder sb = new StringBuilder();
converter.format(event, sb);
final String str = sb.toString();
final String expected = "{}";
assertTrue("Incorrect result. Expected " + expected + ", actual " + str, str.equals(expected));
}
代码示例来源:origin: org.apache.logging.log4j/log4j-api
public static void testPut() {
ThreadContext.clearMap();
assertNull(ThreadContext.get("testKey"));
ThreadContext.put("testKey", "testValue");
assertEquals("testValue", ThreadContext.get("testKey"));
}
}
代码示例来源:origin: org.apache.logging.log4j/log4j-api
@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("Audit@18060", "Transfer Complete", "Transfer");
msg.put("ToAccount", "123456");
msg.put("FromAccount", "123457");
msg.put("Amount", "200.00");
logger.info(MarkerManager.getMarker("EVENT"), msg);
ThreadContext.clearMap();
assertEquals(1, results.size());
assertThat("Incorrect structured data: ", results.get(0), startsWith(
"EVENT INFO Transfer [Audit@18060 Amount=\"200.00\" FromAccount=\"123457\" ToAccount=\"123456\"] Transfer Complete"));
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
@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.clearMap();
// TODO: do something with the results
}
代码示例来源:origin: org.apache.logging.log4j/log4j-api
@Test
public void testContainsKey() {
ThreadContext.clearMap();
assertFalse(ThreadContext.containsKey("testKey"));
ThreadContext.put("testKey", "testValue");
assertTrue(ThreadContext.containsKey("testKey"));
ThreadContext.remove("testKey");
assertFalse(ThreadContext.containsKey("testKey"));
}
代码示例来源:origin: org.apache.logging.log4j/log4j-api
@Test
public void testContainsKey() {
ThreadContext.clearMap();
assertFalse(ThreadContext.containsKey("testKey"));
ThreadContext.put("testKey", "testValue");
assertTrue(ThreadContext.containsKey("testKey"));
ThreadContext.remove("testKey");
assertFalse(ThreadContext.containsKey("testKey"));
}
代码示例来源:origin: org.apache.logging.log4j/log4j-api
@Test
public void testRemove() {
ThreadContext.clearMap();
assertNull(ThreadContext.get("testKey"));
ThreadContext.put("testKey", "testValue");
assertEquals("testValue", ThreadContext.get("testKey"));
ThreadContext.remove("testKey");
assertNull(ThreadContext.get("testKey"));
assertTrue(ThreadContext.isEmpty());
}
代码示例来源:origin: org.apache.logging.log4j/log4j-api
@Test
public void testRemove() {
ThreadContext.clearMap();
assertNull(ThreadContext.get("testKey"));
ThreadContext.put("testKey", "testValue");
assertEquals("testValue", ThreadContext.get("testKey"));
ThreadContext.remove("testKey");
assertNull(ThreadContext.get("testKey"));
assertTrue(ThreadContext.isEmpty());
}
代码示例来源:origin: org.apache.logging.log4j/log4j-api
@Test
public void testRemoveAll() {
ThreadContext.clearMap();
ThreadContext.put("testKey1", "testValue1");
ThreadContext.put("testKey2", "testValue2");
assertEquals("testValue1", ThreadContext.get("testKey1"));
assertEquals("testValue2", ThreadContext.get("testKey2"));
assertFalse(ThreadContext.isEmpty());
ThreadContext.removeAll(Arrays.asList("testKey1", "testKey2"));
assertNull(ThreadContext.get("testKey1"));
assertNull(ThreadContext.get("testKey2"));
assertTrue(ThreadContext.isEmpty());
}
内容来源于网络,如有侵权,请联系作者删除!