本文整理汇总了Java中org.apache.logging.log4j.ThreadContext.getImmutableStack方法的典型用法代码示例。如果您正苦于以下问题:Java ThreadContext.getImmutableStack方法的具体用法?Java ThreadContext.getImmutableStack怎么用?Java ThreadContext.getImmutableStack使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.logging.log4j.ThreadContext
的用法示例。
在下文中一共展示了ThreadContext.getImmutableStack方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: translateTo
import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@Override
public void translateTo(final RingBufferLogEvent event, final long sequence, final Object... args) {
// Implementation note: candidate for optimization: exceeds 35 bytecodes.
final AsyncLogger asyncLogger = (AsyncLogger) args[0];
final StackTraceElement location = (StackTraceElement) args[1];
final String fqcn = (String) args[2];
final Level level = (Level) args[3];
final Marker marker = (Marker) args[4];
final Message message = (Message) args[5];
final Throwable thrown = (Throwable) args[6];
// needs shallow copy to be fast (LOG4J2-154)
final ContextStack contextStack = ThreadContext.getImmutableStack();
final Thread currentThread = Thread.currentThread();
final String threadName = THREAD_NAME_CACHING_STRATEGY.getThreadName();
event.setValues(asyncLogger, asyncLogger.getName(), marker, fqcn, level, message, thrown,
// config properties are taken care of in the EventHandler thread
// in the AsyncLogger#actualAsyncLog method
CONTEXT_DATA_INJECTOR.injectContextData(null, (StringMap) event.getContextData()),
contextStack, currentThread.getId(), threadName, currentThread.getPriority(), location,
CLOCK, nanoClock);
}
示例2: testBuilderCorrectlyCopiesAllEventAttributes
import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@Test
public void testBuilderCorrectlyCopiesAllEventAttributes() {
final StringMap contextData = ContextDataFactory.createContextData();
contextData.putValue("A", "B");
final ContextStack contextStack = ThreadContext.getImmutableStack();
final Exception exception = new Exception("test");
final Marker marker = MarkerManager.getMarker("EVENTTEST");
final Message message = new SimpleMessage("foo");
final StackTraceElement stackTraceElement = new StackTraceElement("A", "B", "file", 123);
final String fqcn = "qualified";
final String name = "Ceci n'est pas une pipe";
final String threadName = "threadName";
final Log4jLogEvent event = Log4jLogEvent.newBuilder() //
.setContextData(contextData) //
.setContextStack(contextStack) //
.setEndOfBatch(true) //
.setIncludeLocation(true) //
.setLevel(Level.FATAL) //
.setLoggerFqcn(fqcn) //
.setLoggerName(name) //
.setMarker(marker) //
.setMessage(message) //
.setNanoTime(1234567890L) //
.setSource(stackTraceElement) //
.setThreadName(threadName) //
.setThrown(exception) //
.setTimeMillis(987654321L)
.build();
assertEquals(contextData, event.getContextData());
assertSame(contextStack, event.getContextStack());
assertEquals(true, event.isEndOfBatch());
assertEquals(true, event.isIncludeLocation());
assertSame(Level.FATAL, event.getLevel());
assertSame(fqcn, event.getLoggerFqcn());
assertSame(name, event.getLoggerName());
assertSame(marker, event.getMarker());
assertSame(message, event.getMessage());
assertEquals(1234567890L, event.getNanoTime());
assertSame(stackTraceElement, event.getSource());
assertSame(threadName, event.getThreadName());
assertSame(exception, event.getThrown());
assertEquals(987654321L, event.getTimeMillis());
final LogEvent event2 = new Log4jLogEvent.Builder(event).build();
assertEquals("copy constructor builder", event2, event);
assertEquals("same hashCode", event2.hashCode(), event.hashCode());
}
示例3: testBuilderCorrectlyCopiesAllEventAttributesInclContextData
import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@Test
public void testBuilderCorrectlyCopiesAllEventAttributesInclContextData() {
final StringMap contextData = new SortedArrayStringMap();
contextData.putValue("A", "B");
final ContextStack contextStack = ThreadContext.getImmutableStack();
final Exception exception = new Exception("test");
final Marker marker = MarkerManager.getMarker("EVENTTEST");
final Message message = new SimpleMessage("foo");
final StackTraceElement stackTraceElement = new StackTraceElement("A", "B", "file", 123);
final String fqcn = "qualified";
final String name = "Ceci n'est pas une pipe";
final String threadName = "threadName";
final Log4jLogEvent event = Log4jLogEvent.newBuilder() //
.setContextData(contextData) //
.setContextStack(contextStack) //
.setEndOfBatch(true) //
.setIncludeLocation(true) //
.setLevel(Level.FATAL) //
.setLoggerFqcn(fqcn) //
.setLoggerName(name) //
.setMarker(marker) //
.setMessage(message) //
.setNanoTime(1234567890L) //
.setSource(stackTraceElement) //
.setThreadName(threadName) //
.setThrown(exception) //
.setTimeMillis(987654321L)
.build();
assertSame(contextData, event.getContextData());
assertSame(contextStack, event.getContextStack());
assertEquals(true, event.isEndOfBatch());
assertEquals(true, event.isIncludeLocation());
assertSame(Level.FATAL, event.getLevel());
assertSame(fqcn, event.getLoggerFqcn());
assertSame(name, event.getLoggerName());
assertSame(marker, event.getMarker());
assertSame(message, event.getMessage());
assertEquals(1234567890L, event.getNanoTime());
assertSame(stackTraceElement, event.getSource());
assertSame(threadName, event.getThreadName());
assertSame(exception, event.getThrown());
assertEquals(987654321L, event.getTimeMillis());
final LogEvent event2 = new Log4jLogEvent.Builder(event).build();
assertEquals("copy constructor builder", event2, event);
assertEquals("same hashCode", event2.hashCode(), event.hashCode());
}
示例4: testBuilderCorrectlyCopiesMutableLogEvent
import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@Test
public void testBuilderCorrectlyCopiesMutableLogEvent() throws Exception {
final StringMap contextData = new SortedArrayStringMap();
contextData.putValue("A", "B");
final ContextStack contextStack = ThreadContext.getImmutableStack();
final Exception exception = new Exception("test");
final Marker marker = MarkerManager.getMarker("EVENTTEST");
final Message message = new SimpleMessage("foo");
new StackTraceElement("A", "B", "file", 123);
final String fqcn = "qualified";
final String name = "Ceci n'est pas une pipe";
final String threadName = "threadName";
final MutableLogEvent event = new MutableLogEvent();
event.setContextData(contextData);
event.setContextStack(contextStack);
event.setEndOfBatch(true);
event.setIncludeLocation(true);
//event.setSource(stackTraceElement); // cannot be explicitly set
event.setLevel(Level.FATAL);
event.setLoggerFqcn(fqcn);
event.setLoggerName(name);
event.setMarker(marker);
event.setMessage(message);
event.setNanoTime(1234567890L);
event.setThreadName(threadName);
event.setThrown(exception);
event.setTimeMillis(987654321L);
assertSame(contextData, event.getContextData());
assertSame(contextStack, event.getContextStack());
assertEquals(true, event.isEndOfBatch());
assertEquals(true, event.isIncludeLocation());
assertSame(Level.FATAL, event.getLevel());
assertSame(fqcn, event.getLoggerFqcn());
assertSame(name, event.getLoggerName());
assertSame(marker, event.getMarker());
assertSame(message, event.getMessage());
assertEquals(1234567890L, event.getNanoTime());
//assertSame(stackTraceElement, event.getSource()); // don't invoke
assertSame(threadName, event.getThreadName());
assertSame(exception, event.getThrown());
assertEquals(987654321L, event.getTimeMillis());
final LogEvent e2 = new Log4jLogEvent.Builder(event).build();
assertEquals(contextData, e2.getContextData());
assertSame(contextStack, e2.getContextStack());
assertEquals(true, e2.isEndOfBatch());
assertEquals(true, e2.isIncludeLocation());
assertSame(Level.FATAL, e2.getLevel());
assertSame(fqcn, e2.getLoggerFqcn());
assertSame(name, e2.getLoggerName());
assertSame(marker, e2.getMarker());
assertSame(message, e2.getMessage());
assertEquals(1234567890L, e2.getNanoTime());
//assertSame(stackTraceElement, e2.getSource()); // don't invoke
assertSame(threadName, e2.getThreadName());
assertSame(exception, e2.getThrown());
assertEquals(987654321L, e2.getTimeMillis());
// use reflection to get value of source field in log event copy:
// invoking the getSource() method would initialize the field
final Field fieldSource = Log4jLogEvent.class.getDeclaredField("source");
fieldSource.setAccessible(true);
final Object value = fieldSource.get(e2);
assertNull("source in copy", value);
}