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


Java ThreadContext.getContext方法代码示例

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


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

示例1: testGetContextReturnsMutableCopy

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
public static void testGetContextReturnsMutableCopy() {
    ThreadContext.clearMap();
    final Map<String, String> map1 = ThreadContext.getContext();
    assertTrue(map1.isEmpty());
    map1.put("K", "val"); // no error
    assertEquals("val", map1.get("K"));

    // adding to copy does not affect thread context map
    assertTrue(ThreadContext.getContext().isEmpty());

    ThreadContext.put("key", "val2");
    final Map<String, String> map2 = ThreadContext.getContext();
    assertEquals(1, map2.size());
    assertEquals("val2", map2.get("key"));
    map2.put("K", "val"); // no error
    assertEquals("val", map2.get("K"));

    // first copy is not affected
    assertNotSame(map1, map2);
    assertEquals(1, map1.size());
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:22,代码来源:ThreadContextUtilityClass.java

示例2: LogContextThreadFactory

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
public LogContextThreadFactory(final String threadNamePrefix) {
	super(threadNamePrefix, ThreadContext.getContext());
}
 
开发者ID:emc-mongoose,项目名称:mongoose-base,代码行数:4,代码来源:LogContextThreadFactory.java

示例3: log

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@Override
public void log(final Marker marker, final String fqcn, final Level level, final Message msg,
                final Throwable throwable) {
    final StringBuilder sb = new StringBuilder();
    // Append date-time if so configured
    if (showDateTime) {
        final Date now = new Date();
        String dateText;
        synchronized (dateFormatter) {
            dateText = dateFormatter.format(now);
        }
        sb.append(dateText);
        sb.append(SPACE);
    }

    sb.append(level.toString());
    sb.append(SPACE);
    if (logName != null && logName.length() > 0) {
        sb.append(logName);
        sb.append(SPACE);
    }
    sb.append(msg.getFormattedMessage());
    if (showContextMap) {
        final Map<String, String> mdc = ThreadContext.getContext();
        if (mdc.size() > 0) {
            sb.append(SPACE);
            sb.append(mdc.toString());
            sb.append(SPACE);
        }
    }
    final Object[] params = msg.getParameters();
    Throwable t;
    if (throwable == null && params != null && params[params.length - 1] instanceof Throwable) {
        t = (Throwable) params[params.length - 1];
    } else {
        t = throwable;
    }
    if (t != null) {
        sb.append(SPACE);
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        t.printStackTrace(new PrintStream(baos));
        sb.append(baos.toString());
    }
    stream.println(sb.toString());
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:46,代码来源:SimpleLogger.java

示例4: getCopyOfContextMap

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@Override
public Map<String, String> getCopyOfContextMap() {
    return ThreadContext.getContext();
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:5,代码来源:Log4jMDCAdapter.java


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