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


Java ThreadContext.put方法代码示例

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


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

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

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

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

示例4: 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;
    }
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:18,代码来源:MCRSessionThreadContext.java

示例5: complete

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@Override
public void complete(final Channel channel, final O ioTask) {

	ThreadContext.put(KEY_CLASS_NAME, CLS_NAME);
	ThreadContext.put(KEY_TEST_STEP_ID, stepId);

	try {
		ioTask.finishResponse();
	} catch(final IllegalStateException e) {
		LogUtil.exception(Level.DEBUG, e, "{}: invalid I/O task state", ioTask.toString());
	}
	if(channel != null) {
		connPool.release(channel);
	}
	ioTaskCompleted(ioTask);
}
 
开发者ID:emc-mongoose,项目名称:mongoose-base,代码行数:17,代码来源:NetStorageDriverBase.java

示例6: initMerchantLogger

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
protected void initMerchantLogger() {
    ApplicationContext appCtx = App.get().context();

    Merchant merchant = appCtx.getMerchant();
    Store store = appCtx.getStore();

    String logPath = merchant.getLogPath();
    // Log4j does not like backslashes in directory path.
    logPath = logPath.replace(Char.BACKSLASH, Char.SLASH);

    ThreadContext.put("log.route.name", "CB-App-Rolling-Log");
    ThreadContext.put("log.path", logPath);
    ThreadContext.put("appctx.merchant", merchant.getCompanyName());
    ThreadContext.put("appctx.store", store.getName());

    log = LogManager.getLogger(getClass());
}
 
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:18,代码来源:ApplicationInitFilter.java

示例7: doFilterInternal

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@Override
public void doFilterInternal(final HttpServletRequest request,
        final HttpServletResponse response, final FilterChain fc)
        throws IOException, ServletException {
    String allowedMtds = (RequestMethod.GET.name() + "," + 
            RequestMethod.POST.name() + "," + RequestMethod.PATCH.name());
    response.setHeader(HttpHeaders.SERVER, "FAIR data point (JAVA)");
    response.setHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, "*");
    response.setHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS, 
            HttpHeaders.CONTENT_TYPE);
    response.setHeader(HttpHeaders.ALLOW, allowedMtds);
    response.setHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_METHODS,
            (HttpHeaders.ACCEPT));
    ThreadContext.put("ipAddress", request.getRemoteAddr());
    ThreadContext.put("responseStatus", String.valueOf(
            response.getStatus()));
    fc.doFilter(request, response);
    ThreadContext.clearAll();
}
 
开发者ID:DTL-FAIRData,项目名称:FAIRDataPoint,代码行数:20,代码来源:ApplicationFilter.java

示例8: testName

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@Test
public void testName() throws Exception {
    // Log in Main Thread
    logger.info("Log in main!");

    final ExecutorService executorService = Executors.newFixedThreadPool(2);

    // Run task in thread pool
    executorService.submit(createTask()).get();

    // Init Log Context, set TTL
    // More KV if needed
    final String TRACE_ID = "trace-id";
    final String TRACE_ID_VALUE = "XXX-YYY-ZZZ";
    ThreadContext.put(TRACE_ID, TRACE_ID_VALUE);

    // Log in Main Thread
    logger.info("Log in main!");
    executorService.submit(createTask()).get();

    logger.info("Exit main");
    executorService.shutdown();
}
 
开发者ID:oldratlee,项目名称:log4j2-ttl-thread-context-map,代码行数:24,代码来源:TtlThreadContextMapTest.java

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

示例10: setThreadLoggingContext

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
private void setThreadLoggingContext(Message msg) {
    ThreadContext.clearAll();

    if (msg instanceof APIMessage) {
        ThreadContext.put(Constants.THREAD_CONTEXT_API, msg.getId());
        ThreadContext.put(Constants.THREAD_CONTEXT_TASK_NAME, msg.getClass().getName());
    } else {
        Map<String, String> ctx = msg.getHeaderEntry(TASK_CONTEXT);
        if (ctx != null) {
            ThreadContext.putAll(ctx);
        }
    }

    if (msg.getHeaders().containsKey(TASK_STACK)) {
        List<String> taskStack = msg.getHeaderEntry(TASK_STACK);
        ThreadContext.setStack(taskStack);
    }
}
 
开发者ID:zstackio,项目名称:zstack,代码行数:19,代码来源:CloudBusImpl2.java

示例11: run

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@Override
public void run() {
    try {
        boolean successful = false;

        Thread.currentThread().setName( "FetchThread[" + source.sourceId() + "]" );
        ThreadContext.put("sourceId", source.sourceId());

        EventBusManager.fire( new SourceFetchStartedEvent( source.sourceId(), numRules, System.currentTimeMillis() ) );
        successful = source.load( timestamp, now, handler );
        EventBusManager.fire( new SourceFetchFinishedEvent( source.sourceId(), System.currentTimeMillis(), successful ) );

        Thread.currentThread().setName( "FetchThread[none]" );
        ThreadContext.put("sourceId", "[none]");
    } catch ( Exception e ) {
        log.warn( "A totally unexpected exception occured during single fetch: ", e );
    }
}
 
开发者ID:Tetha,项目名称:bifroest,代码行数:19,代码来源:Fetcher.java

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

示例13: 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);
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:23,代码来源:InterpolatorTest.java

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

示例15: setUpDirs

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
public static void setUpDirs() {
	TEMPDIR = FileUtil.findDirectory(getRunDir(), "temp");
	INSTANCEDIR = FileUtil.findDirectory(getRunDir(), "instances");
	LOGFILE = FileUtil.findDirectory(getRunDir(), "logs");
	ICONDIR = FileUtil.findDirectory(Constants.TEMPDIR, "images");
	MINECRAFTDIR = FileUtil.findDirectory(getRunDir(), "minecraft");
	EXPORTS = FileUtil.findDirectory(getRunDir(), "exports");
	MODPACKICON = new File(getRunDir(), "modpack.png");
	ThreadContext.put("logs", LOGFILE.toString());
	OneClientLogging.init();
}
 
开发者ID:HearthProject,项目名称:OneClient,代码行数:12,代码来源:Constants.java


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