當前位置: 首頁>>代碼示例>>Java>>正文


Java MDC.setContextMap方法代碼示例

本文整理匯總了Java中org.slf4j.MDC.setContextMap方法的典型用法代碼示例。如果您正苦於以下問題:Java MDC.setContextMap方法的具體用法?Java MDC.setContextMap怎麽用?Java MDC.setContextMap使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.slf4j.MDC的用法示例。


在下文中一共展示了MDC.setContextMap方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: handler

import org.slf4j.MDC; //導入方法依賴的package包/類
public void handler(CloudwatchEvent event) throws ExecutionException, InterruptedException {
    LOG.info("Received event = [{}]", event.getId());
    final Metrics metrics = new Metrics();

    // Pass Mapped Diagnostic Context (MDC) into child thread, for logging Request ID
    final Map<String, String> contextMap = MDC.getCopyOfContextMap();
    Runnable task = () -> {
        if (contextMap != null) {
            MDC.setContextMap(contextMap);
        }
        LOG.info("Starting fibonacci task");
        timedFibonacci(metrics);
    };

    // Start one task in the background, and one in this thread
    Future<?> future = executorService.submit(task);
    task.run();

    // Wait for background task, log out metrics
    future.get();
    metrics.report(LOG);
}
 
開發者ID:symphoniacloud,項目名稱:jvm-perftest-lambda,代碼行數:23,代碼來源:FibonacciLambda.java

示例2: call

import org.slf4j.MDC; //導入方法依賴的package包/類
public T call() throws Exception {
  MDC.setContextMap(contextMap);
  try {
    return target.call();
  }
  finally {
    MDC.clear();
  }
}
 
開發者ID:zacharee,項目名稱:RCTDRemoverforLG,代碼行數:10,代碼來源:MDCCallableAdapter.java

示例3: call

import org.slf4j.MDC; //導入方法依賴的package包/類
@Override
public K call() throws Exception {
    LOG.debug("Call using MDCHystrixContextCallable...");
    Map childMDC = MDC.getCopyOfContextMap();
    LOG.debug("childMDC --> " + childMDC);
    try {
        if (parentMDC != null) {
            MDC.setContextMap(parentMDC);
        }
        LOG.debug("parentMDC --> " + parentMDC);
        return actual.call();
    } finally {
        if (childMDC != null) {
            MDC.setContextMap(childMDC);
        }
    }
}
 
開發者ID:PacktPublishing,項目名稱:Mastering-Microservices-with-Java-9-Second-Edition,代碼行數:18,代碼來源:MDCConcurrentCallable.java

示例4: run

import org.slf4j.MDC; //導入方法依賴的package包/類
public void run() {
  MDC.setContextMap(contextMap);
  try {
    target.run();
  }
  finally {
    MDC.clear();
  }
}
 
開發者ID:zacharee,項目名稱:RCTDRemoverforLG,代碼行數:10,代碼來源:MDCRunnableAdapter.java

示例5: decorate

import org.slf4j.MDC; //導入方法依賴的package包/類
@Override
public Runnable decorate(Runnable runnable) {
    Map<String, String> contextMap = MDC.getCopyOfContextMap();
    return () -> {
        try {
            MDC.setContextMap(contextMap);
            runnable.run();
        } finally {
            MDC.clear();
        }
    };
}
 
開發者ID:redhat-developer,項目名稱:che-starter,代碼行數:13,代碼來源:MdcTaskDecorator.java

示例6: run

import org.slf4j.MDC; //導入方法依賴的package包/類
@Override
public void run() {
    RequestContextAccessor.set(requestContext);

    if (mdcContents != null) {
        MDC.setContextMap(mdcContents);
    }

    runnable.run();

    MDC.clear();
    RequestContextAccessor.remove();
}
 
開發者ID:Atypon-OpenSource,項目名稱:wayf-cloud,代碼行數:14,代碼來源:WayfRunnable.java

示例7: run

import org.slf4j.MDC; //導入方法依賴的package包/類
@Override
public void run() {
	// we are in the execution thread: set the original MDC
	MDC.setContextMap(map);
	wrapped.run();
}
 
開發者ID:Orange-OpenSource,項目名稱:orange-mathoms-logging,代碼行數:7,代碼來源:RunnableWrapperWithMdc.java

示例8: call

import org.slf4j.MDC; //導入方法依賴的package包/類
@Override
public T call() throws Exception {
	// we are in the execution thread: set the original MDC
	MDC.setContextMap(map);
	return wrapped.call();
}
 
開發者ID:Orange-OpenSource,項目名稱:orange-mathoms-logging,代碼行數:7,代碼來源:CallableWrapperWithMdc.java


注:本文中的org.slf4j.MDC.setContextMap方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。