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


Java MDC.getCopyOfContextMap方法代码示例

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


在下文中一共展示了MDC.getCopyOfContextMap方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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包/类
@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

示例3: wrapTask

import org.slf4j.MDC; //导入方法依赖的package包/类
/**
 * Override this to customize how the background task is created.
 *
 * @param task the task to be run in the background
 * @return the runnable of the wrapped task
 */
protected Runnable wrapTask(Runnable task) {
  // Preserve the MDC context of the caller thread.
  Map contextMap = MDC.getCopyOfContextMap();
  if (contextMap != null) {
    return new MDCRunnableAdapter(task, contextMap);
  }
  return task;
}
 
开发者ID:zacharee,项目名称:RCTDRemoverforLG,代码行数:15,代码来源:PumpStreamHandler.java

示例4: wrapTask

import org.slf4j.MDC; //导入方法依赖的package包/类
/**
 * Override this to customize how the background task is created.
 *
 * @param <T> the type of the Task
 * @param task the Task to be wrapped
 * @return the wrapped task
 */
protected <T> Callable<T> wrapTask(Callable<T> task) {
  // Preserve the MDC context of the caller thread.
  Map contextMap = MDC.getCopyOfContextMap();
  if (contextMap != null) {
    return new MDCCallableAdapter(task, contextMap);
  }
  return task;
}
 
开发者ID:zacharee,项目名称:RCTDRemoverforLG,代码行数:16,代码来源:ProcessExecutor.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: MDCConcurrentCallable

import org.slf4j.MDC; //导入方法依赖的package包/类
public MDCConcurrentCallable(Callable<K> actual) {
    LOG.debug("Init MDCHystrixContextCallable...");
    this.actual = actual;
    this.parentMDC = MDC.getCopyOfContextMap();
    LOG.debug("actual --> " + actual);
    LOG.debug("this.parentMDC --> " + this.parentMDC);
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Microservices-with-Java-9-Second-Edition,代码行数:8,代码来源:MDCConcurrentCallable.java

示例7: format

import org.slf4j.MDC; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public String format(final LogRecord record) {
    // Reset working buffer. If the buffer is too large, then we need a new
    // one in order to avoid the penalty of creating a large array.
    if (buf.capacity() > UPPER_LIMIT) {
        buf = new StringBuffer(DEFAULT_SIZE);
    } else {
        buf.setLength(0);
    }
    buf.append("<log4j:event logger=\"");
    buf.append(Transform.escapeTags(record.getLoggerName()));
    buf.append("\" timestamp=\"");
    buf.append(record.getMillis());
    buf.append("\" level=\"");

    buf.append(Transform.escapeTags(record.getLevel().getName()));
    buf.append("\" thread=\"");
    buf.append(String.valueOf(record.getThreadID()));
    buf.append("\">\r\n");

    buf.append("<log4j:message><![CDATA[");
    // Append the rendered message. Also make sure to escape any
    // existing CDATA sections.
    Transform.appendEscapingCDATA(buf, record.getMessage());
    buf.append("]]></log4j:message>\r\n");

    if (record.getThrown() != null) {
        String[] s = Transform.getThrowableStrRep(record.getThrown());
        if (s != null) {
            buf.append("<log4j:throwable><![CDATA[");
            for (String value : s) {
                Transform.appendEscapingCDATA(buf, value);
                buf.append("\r\n");
            }
            buf.append("]]></log4j:throwable>\r\n");
        }
    }

    if (locationInfo) {
        buf.append("<log4j:locationInfo class=\"");
        buf.append(Transform.escapeTags(record.getSourceClassName()));
        buf.append("\" method=\"");
        buf.append(Transform.escapeTags(record.getSourceMethodName()));
        buf.append("\" file=\"?\" line=\"?\"/>\r\n");
    }

    if (properties) {
        Map contextMap = MDC.getCopyOfContextMap();
        if (contextMap != null) {
            Set keySet = contextMap.keySet();
            if ((keySet != null) && (keySet.size() > 0)) {
                buf.append("<log4j:properties>\r\n");
                Object[] keys = keySet.toArray();
                Arrays.sort(keys);
                for (Object key1 : keys) {
                    String key = (key1 == null ? "" : key1.toString());
                    Object val = contextMap.get(key);
                    if (val != null) {
                        buf.append("<log4j:data name=\"");
                        buf.append(Transform.escapeTags(key));
                        buf.append("\" value=\"");
                        buf.append(Transform.escapeTags(String.valueOf(val)));
                        buf.append("\"/>\r\n");
                    }
                }
                buf.append("</log4j:properties>\r\n");
            }
        }

    }
    buf.append("</log4j:event>\r\n\r\n");

    return buf.toString();
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:76,代码来源:Log4jXmlFormatter.java

示例8: RunnableWrapperWithMdc

import org.slf4j.MDC; //导入方法依赖的package包/类
public RunnableWrapperWithMdc(Runnable wrapped) {
	this.wrapped = wrapped;
	// we are in the origin thread: capture the MDC
	map = MDC.getCopyOfContextMap();
}
 
开发者ID:Orange-OpenSource,项目名称:orange-mathoms-logging,代码行数:6,代码来源:RunnableWrapperWithMdc.java

示例9: CallableWrapperWithMdc

import org.slf4j.MDC; //导入方法依赖的package包/类
public CallableWrapperWithMdc(Callable<T> wrapped) {
	this.wrapped = wrapped;
	// we are in the origin thread: capture the MDC
	map = MDC.getCopyOfContextMap();
}
 
开发者ID:Orange-OpenSource,项目名称:orange-mathoms-logging,代码行数:6,代码来源:CallableWrapperWithMdc.java

示例10: WayfRunnable

import org.slf4j.MDC; //导入方法依赖的package包/类
public WayfRunnable(Runnable runnable) {
    this.runnable = runnable;
    this.requestContext = RequestContextAccessor.get();
    this.mdcContents = MDC.getCopyOfContextMap();
}
 
开发者ID:Atypon-OpenSource,项目名称:wayf-cloud,代码行数:6,代码来源:WayfRunnable.java


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