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


Java ThreadContext.remove方法代码示例

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


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

示例1: invoke

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
@Override
public void invoke(Event event)
{
    if (GETCONTEXT)
        ThreadContext.put("mod", owner == null ? "" : owner.getName());
    if (handler != null)
    {
        if (!event.isCancelable() || !event.isCanceled() || subInfo.receiveCanceled())
        {
            if (filter == null || filter == ((IGenericEvent)event).getGenericType())
            {
                handler.invoke(event);
            }
        }
    }
    if (GETCONTEXT)
        ThreadContext.remove("mod");
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:20,代码来源:ASMEventHandler.java

示例2: invoke

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@Override
public void invoke(Event event)
{
    if (owner != null && GETCONTEXT)
    {
        ThreadContext.put("mod", owner.getName());
    }
    else if (GETCONTEXT)
    {
        ThreadContext.put("mod", "");
    }
    if (handler != null)
    {
        if (!event.isCancelable() || !event.isCanceled() || subInfo.receiveCanceled())
        {
            handler.invoke(event);
        }
    }
    if (GETCONTEXT)
        ThreadContext.remove("mod");
}
 
开发者ID:SchrodingersSpy,项目名称:TRHS_Club_Mod_2016,代码行数:22,代码来源:ASMEventHandler.java

示例3: doFilter

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
		throws IOException, ServletException {
	String id = UUID.randomUUID().toString();
	ThreadContext.put("id", id);
	try {
		HttpServletResponse resp = (HttpServletResponse) response;
		resp.setHeader("Log-ID", id);
		chain.doFilter(request, response);
	} catch (Throwable e) {
		logger.error("error", e);
	} finally {
		ThreadContext.remove("id");
		ThreadContext.remove("username");
	}

}
 
开发者ID:shilongdai,项目名称:bookManager,代码行数:18,代码来源:PreSescLoggingFilter.java

示例4: invoke

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@Override
public void invoke(Event event)
{
    if (owner != null)
    {
        ThreadContext.put("mod", owner.getName());
    }
    else
    {
        ThreadContext.put("mod", "");
    }
    if (handler != null)
    {
        if (!event.isCancelable() || !event.isCanceled() || subInfo.receiveCanceled())
        {
            handler.invoke(event);
        }
    }
    ThreadContext.remove("mod");
}
 
开发者ID:alexandrage,项目名称:CauldronGit,代码行数:21,代码来源:ASMEventHandler.java

示例5: sendBatch

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
private void sendBatch(ConcurrentBiMap<Document, T> oldBatch) {
  // there's a small window where the same BiMap could be grabbed by a timer and a full batch causing a double
  // send. Thus we have a lock to ensure that the oldBatch.clear() in the finally is called
  // before the second thread tries to send the same batch. We tolerate this because it means batches can fill up
  // while sending is in progress.
  synchronized (sendLock) {
    if (oldBatch.size() == 0) {
      return;
    }
    try {
      batchOperation(oldBatch);
    } catch (Exception e) {
      // we may have a single bad document...
      //noinspection ConstantConditions
      if (exceptionIndicatesDocumentIssue(e)) {
        individualFallbackOperation(oldBatch, e);
      } else {
        perDocumentFailure(oldBatch, e);
      }
    } finally {
      ThreadContext.remove(JesterJAppender.JJ_INGEST_DOCID);
      ThreadContext.remove(JesterJAppender.JJ_INGEST_SOURCE_SCANNER);
      oldBatch.clear();
    }
  }
}
 
开发者ID:nsoft,项目名称:jesterj,代码行数:27,代码来源:BatchProcessor.java

示例6: run

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@Override
public void run()
{
    try
    {
        Thread.sleep(200);
    }
    catch (InterruptedException e)
    {
    }

    if (details)
    {
        ThreadContext.put("key2", "value2");
        ThreadContext.put("key4", "value4");
        logger.error("Some message", new Exception("Error"));
        ThreadContext.remove("key2");
        ThreadContext.remove("key4");
    }
    else
    {
        logger.info("Hello World!");
    }
}
 
开发者ID:viskan,项目名称:logstash-appender,代码行数:25,代码来源:LogstashAppenderTest.java

示例7: apply

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@Override
public Statement apply(final Statement base, final Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            final File logFile = new File("target",
                description.getClassName() + '.' + description.getMethodName() + ".log");
            ThreadContext.put("testClassName", description.getClassName());
            ThreadContext.put("testMethodName", description.getMethodName());
            try {
                base.evaluate();
            } finally {
                ThreadContext.remove("testClassName");
                ThreadContext.remove("testMethodName");
                if (logFile.exists()) {
                    logFile.deleteOnExit();
                }
            }
        }
    };
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:22,代码来源:ContextMapLookupTest.java

示例8: process

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@Override
public void process(Exchange exchange) throws Exception {
  try {
    String requestId = exchange.getProperty(RequestIdManager.REQUEST_ID, String.class);
    ThreadContext.put(RequestIdManager.REQUEST_ID, requestId);
    doProcess(exchange);
  } finally {
    ThreadContext.remove(RequestIdManager.REQUEST_ID);
  }
}
 
开发者ID:eXcellme,项目名称:eds,代码行数:11,代码来源:AbstractLogicConsumer.java

示例9: baseCleanup

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@AfterMethod(alwaysRun = true)
public void baseCleanup(ITestContext context, ITestResult result, Object[] params) throws IOException {
	if (params.length > 0 && params[0] instanceof WebDriverInstance){
		WebDriverInstance webDriverInstance = (WebDriverInstance)params[0];
		webDriverInstance.cleanup();
	}
	logTestResult(result);
	String tag = ThreadContext.get(THREAD_TAG);
	logger.info("Test is finished, removing the tag [{}]...", tag);
	ThreadContext.remove(THREAD_TAG);
	result.setAttribute(THREAD_TAG, tag);
}
 
开发者ID:3pillarlabs,项目名称:AutomationFrameworkTPG,代码行数:13,代码来源:TestBase.java

示例10: sendEventToModContainer

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
private void sendEventToModContainer(FMLEvent stateEvent, ModContainer mc)
{
    String modId = mc.getModId();
    Collection<String> requirements =  Collections2.transform(mc.getRequirements(),new ArtifactVersionNameFunction());
    for (ArtifactVersion av : mc.getDependencies())
    {
        if (av.getLabel()!= null && requirements.contains(av.getLabel()) && modStates.containsEntry(av.getLabel(),ModState.ERRORED))
        {
            FMLLog.log(modId, Level.ERROR, "Skipping event %s and marking errored mod %s since required dependency %s has errored", stateEvent.getEventType(), modId, av.getLabel());
            modStates.put(modId, ModState.ERRORED);
            return;
        }
    }
    activeContainer = mc;
    stateEvent.applyModContainer(activeContainer());
    ThreadContext.put("mod", modId);
    FMLLog.log(modId, Level.TRACE, "Sending event %s to mod %s", stateEvent.getEventType(), modId);
    eventChannels.get(modId).post(stateEvent);
    FMLLog.log(modId, Level.TRACE, "Sent event %s to mod %s", stateEvent.getEventType(), modId);
    ThreadContext.remove("mod");
    activeContainer = null;
    if (stateEvent instanceof FMLStateEvent)
    {
        if (!errors.containsKey(modId))
        {
            modStates.put(modId, ((FMLStateEvent)stateEvent).getModState());
        }
        else
        {
            modStates.put(modId, ModState.ERRORED);
        }
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:34,代码来源:LoadController.java

示例11: tearDown

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@After
public void tearDown()
throws Exception {
	stdOutStream.close();
	ThreadContext.remove(KEY_TEST_STEP_ID);
	//LogUtil.shutdown();
}
 
开发者ID:emc-mongoose,项目名称:mongoose-base,代码行数:8,代码来源:LoggingTestBase.java

示例12: 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

示例13: testLayout

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
/**
 * Test case for MDC conversion pattern.
 */
@Test
public void testLayout() throws Exception {

    // set up appender
    final XMLLayout layout = XMLLayout.createLayout("true", "true", "true", null, null, null);
    final ListAppender appender = new ListAppender("List", null, layout, true, false);
    appender.start();

    // set appender on root and set level to debug
    root.addAppender(appender);
    root.setLevel(Level.DEBUG);

    // output starting message
    root.debug("starting mdc pattern test");

    root.debug("empty mdc");

    ThreadContext.put("key1", "value1");
    ThreadContext.put("key2", "value2");

    root.debug("filled mdc");

    ThreadContext.remove("key1");
    ThreadContext.remove("key2");

    root.error("finished mdc pattern test", new NullPointerException("test"));

    appender.stop();

    final List<String> list = appender.getMessages();

    assertTrue("Incorrect number of lines. Require at least 50 " + list.size(), list.size() > 50);
    final String string = list.get(0);
    assertTrue("Incorrect header: " + string, string.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
    assertTrue("Incorrect footer", list.get(list.size() - 1).equals("</Events>"));
    assertTrue("Incorrect body. Expected " + body + " Actual: " + list.get(7), list.get(7).trim().equals(body));
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:41,代码来源:XMLLayoutTest.java

示例14: after

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@After
public void after() {
    ThreadContext.remove("foo");
    ThreadContext.remove("baz");
    System.clearProperty("log4j2.threadContextMap");
    System.clearProperty("log4j2.isThreadContextMapInheritable");
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:8,代码来源:ThreadContextDataInjectorTest.java

示例15: prepareThreadContext

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
private void prepareThreadContext(boolean isThreadContextMapInheritable) {
    System.setProperty("log4j2.isThreadContextMapInheritable", Boolean.toString(isThreadContextMapInheritable));
    PropertiesUtil.getProperties().reload();
    ThreadContextTest.reinitThreadContext();
    ThreadContext.remove("baz");
    ThreadContext.put("foo", "bar");
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:8,代码来源:ThreadContextDataInjectorTest.java


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