本文整理汇总了Java中org.apache.logging.log4j.ThreadContext.clearMap方法的典型用法代码示例。如果您正苦于以下问题:Java ThreadContext.clearMap方法的具体用法?Java ThreadContext.clearMap怎么用?Java ThreadContext.clearMap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.logging.log4j.ThreadContext
的用法示例。
在下文中一共展示了ThreadContext.clearMap方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sessionEvent
import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@Override
public void sessionEvent(MCRSessionEvent event) {
switch (event.getType()) {
case activated:
ThreadContext.put("ipAddress", event.getSession().getCurrentIP());
ThreadContext.put("loginId", event.getSession().getUserInformation().getUserID());
ThreadContext.put("mcrSession", event.getSession().getID());
ThreadContext.put("language", event.getSession().getCurrentLanguage());
break;
case passivated:
ThreadContext.clearMap();
break;
default:
break;
}
}
示例2: beforeExecute
import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@Override
protected void beforeExecute(Thread t, Runnable r) {
ThreadContext.clearMap();
ThreadContext.clearStack();
ThreadAroundHook debugHook = null;
List<ThreadAroundHook> tmpHooks;
synchronized (_hooks) {
tmpHooks = new ArrayList<ThreadAroundHook>(_hooks);
}
for (ThreadAroundHook hook : tmpHooks) {
debugHook = hook;
try {
hook.beforeExecute(t, r);
} catch (Exception e) {
_logger.warn("Unhandle exception happend during executing ThreadAroundHook: " + debugHook.getClass().getCanonicalName(), e);
}
}
}
示例3: afterExecute
import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@Override
protected void afterExecute(Runnable r, Throwable t) {
ThreadContext.clearMap();
ThreadContext.clearStack();
ThreadAroundHook debugHook = null;
List<ThreadAroundHook> tmpHooks;
synchronized (_hooks) {
tmpHooks = new ArrayList<ThreadAroundHook>(_hooks);
}
for (ThreadAroundHook hook : tmpHooks) {
debugHook = hook;
try {
hook.afterExecute(r, t);
} catch (Exception e) {
_logger.warn("Unhandle exception happend during executing ThreadAroundHook: " + debugHook.getClass().getCanonicalName(), e);
}
}
}
示例4: perfTest
import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
public static void perfTest() throws Exception {
ThreadContext.clearMap();
final Timer complete = new Timer("ThreadContextTest");
complete.start();
ThreadContext.put("Var1", "value 1");
ThreadContext.put("Var2", "value 2");
ThreadContext.put("Var3", "value 3");
ThreadContext.put("Var4", "value 4");
ThreadContext.put("Var5", "value 5");
ThreadContext.put("Var6", "value 6");
ThreadContext.put("Var7", "value 7");
ThreadContext.put("Var8", "value 8");
ThreadContext.put("Var9", "value 9");
ThreadContext.put("Var10", "value 10");
final int loopCount = 1000000;
final Timer timer = new Timer("ThreadContextCopy", loopCount);
timer.start();
for (int i = 0; i < loopCount; ++i) {
final Map<String, String> map = ThreadContext.getImmutableContext();
assertNotNull(map);
}
timer.stop();
complete.stop();
System.out.println(timer.toString());
System.out.println(complete.toString());
}
示例5: testLookup
import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@Test
public void testLookup() {
final Map<String, String> map = new HashMap<>();
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("SYS:" + TESTKEY2);
assertEquals(TESTVAL, value);
value = lookup.lookup("BadKey");
assertNull(value);
ThreadContext.clearMap();
value = lookup.lookup("ctx:" + TESTKEY);
assertEquals(TESTVAL, value);
value = lookup.lookup("jndi:" + TEST_CONTEXT_RESOURCE_NAME);
assertEquals(TEST_CONTEXT_NAME, value);
}
示例6: LoggingApp
import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
public LoggingApp(final String member) {
ThreadContext.clearMap();
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);
}
}
示例7: testConverterFullEmpty
import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@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));
}
示例8: testJavascriptFilter
import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@Test
public void testJavascriptFilter() throws Exception {
final Logger logger = LogManager.getLogger("TestJavaScriptFilter");
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");
final List<String> messages = app.getMessages();
try {
assertNotNull("No Messages", messages);
assertTrue("Incorrect number of messages. Expected 2, Actual " + messages.size(), messages.size() == 2);
} finally {
app.clear();
}
}
示例9: 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.clearMap();
// TODO: do something with the results
}
示例10: before
import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@Override
protected void before() throws Throwable {
threadContextHolder = new ThreadContextHolder(restoreMap, restoreStack);
if (restoreMap) {
ThreadContext.clearMap();
}
if (restoreStack) {
ThreadContext.clearStack();
}
}
示例11: 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.clearMap();
for (final Map.Entry<String, String> entry : ((Map<String, String>) map).entrySet()) {
ThreadContext.put(entry.getKey(), entry.getValue());
}
}
示例12: mdc
import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void mdc() {
ThreadContext.put("TestYear", Integer.toString(2010));
logger.debug("Debug message");
ThreadContext.clearMap();
logger.debug("Debug message");
assertThat(list.strList, hasSize(2));
assertTrue("Incorrect year", list.strList.get(0).startsWith("2010"));
}
示例13: mdc
import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@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());
}
示例14: 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.clearMap();
final List<LogEvent> events = app.getEvents();
assertEquals("Incorrect number of events. Expected 1, actual " + events.size(), 1, events.size());
}
示例15: clearAndPut
import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
public void clearAndPut() {
ThreadContext.clearMap();
for (int i = 0; i < count; i++) {
ThreadContext.put(keys[i], values[i]);
}
}