本文整理了Java中org.apache.logging.log4j.ThreadContext.push()
方法的一些代码示例,展示了ThreadContext.push()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ThreadContext.push()
方法的具体详情如下:
包路径:org.apache.logging.log4j.ThreadContext
类名称:ThreadContext
方法名:push
[英]Pushes new diagnostic context information for the current thread.
The contents of the message
parameter is determined solely by the client.
[中]为当前线程推送新的诊断上下文信息。message
参数的内容完全由客户端决定。
代码示例来源:origin: org.apache.logging.log4j/log4j-api
/**
* Pushes new diagnostic context information on to the Thread Context Stack. The information will be popped off when
* the instance is closed.
*
* @param message The new diagnostic context information.
* @return the instance that will back out the changes when closed.
*/
public Instance push(final String message) {
ThreadContext.push(message);
pushCount++;
return this;
}
代码示例来源:origin: org.apache.logging.log4j/log4j-api
/**
* Pushes new diagnostic context information on to the Thread Context Stack. The information will be popped off when
* the instance is closed.
*
* @param message The new diagnostic context information.
* @param args Parameters for the message.
* @return the instance that will back out the changes when closed.
*/
public Instance push(final String message, final Object[] args) {
ThreadContext.push(message, args);
pushCount++;
return this;
}
代码示例来源:origin: wildfly/wildfly
@Override
public void pushNdc(String message) {
ThreadContext.push(message);
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
@Test
public void test3() {
ThreadContext.push("foo");
ThreadContext.push("bar");
ThreadContext.push("baz");
testConverter("[foo, bar, baz]");
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
@Test
public void test2() {
ThreadContext.push("foo");
ThreadContext.push("bar");
testConverter("[foo, bar]");
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
@Test
public void test1() {
ThreadContext.push("foo");
testConverter("[foo]");
}
代码示例来源:origin: org.apache.logging.log4j/log4j-api
@Test
public void testPush() {
ThreadContext.push("Hello");
ThreadContext.push("{} is {}", ThreadContextTest.class.getSimpleName(),
"running");
assertEquals("Incorrect parameterized stack value",
ThreadContext.pop(), "ThreadContextTest is running");
assertEquals("Incorrect simple stack value", ThreadContext.pop(),
"Hello");
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
@Test
public void testAsyncLogWritesToLog() throws Exception {
final File file = new File("target", "AsyncLoggerTest.log");
// System.out.println(f.getAbsolutePath());
file.delete();
ThreadContext.push("stackvalue");
ThreadContext.put("KEY", "mapvalue");
final Logger log = LogManager.getLogger("com.foo.Bar");
final String msg = "Async logger msg";
log.info(msg, new InternalError("this is not a real error"));
CoreLoggerContexts.stopLoggerContext(false, file); // stop async thread
final BufferedReader reader = new BufferedReader(new FileReader(file));
final String line1 = reader.readLine();
reader.close();
file.delete();
assertNotNull("line1", line1);
assertTrue("line1 correct", line1.contains(msg));
assertTrue("ThreadContext.map", line1.contains("mapvalue"));
assertTrue("ThreadContext.stack", line1.contains("stackvalue"));
}
代码示例来源:origin: org.apache.logging.log4j/log4j-api
@Test
public void testPush() {
ThreadContext.push("Hello");
ThreadContext.push("{} is {}", ThreadContextInheritanceTest.class.getSimpleName(),
"running");
assertEquals("Incorrect parameterized stack value",
ThreadContext.pop(), "ThreadContextInheritanceTest is running");
assertEquals("Incorrect simple stack value", ThreadContext.pop(),
"Hello");
}
代码示例来源:origin: org.apache.logging.log4j/log4j-api
@Test
public void pushAllWillPushAllValues() throws Exception {
ThreadContext.push(key);
final List<String> messages = ThreadContext.getImmutableStack().asList();
ThreadContext.pop();
try (final CloseableThreadContext.Instance ignored = CloseableThreadContext.pushAll(messages)) {
assertThat(ThreadContext.peek(), is(key));
}
assertThat(ThreadContext.peek(), is(""));
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
ThreadContext.push("stackvalue");
ThreadContext.put("KEY", "mapvalue");
代码示例来源:origin: org.apache.logging.log4j/log4j-api
@Test
public void closeIsIdempotent() throws Exception {
final String originalMapValue = "map to keep";
final String originalStackValue = "stack to keep";
ThreadContext.put(key, originalMapValue);
ThreadContext.push(originalStackValue);
final String newMapValue = "temp map value";
final String newStackValue = "temp stack to keep";
final CloseableThreadContext.Instance ctc = CloseableThreadContext.push(newStackValue).put(key, newMapValue);
ctc.close();
assertThat(ThreadContext.get(key), is(originalMapValue));
assertThat(ThreadContext.peek(), is(originalStackValue));
ctc.close();
assertThat(ThreadContext.get(key), is(originalMapValue));
assertThat(ThreadContext.peek(), is(originalStackValue));
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
context.put("user", "pass");
ThreadContext.push("message1");
ThreadContext.push("stack2");
final ThreadContext.ContextStack stack = ThreadContext.getImmutableStack();
ThreadContext.clearStack();
代码示例来源:origin: org.apache.logging.log4j/log4j-core
context.put("user", "pass");
ThreadContext.push("message1");
ThreadContext.push("stack2");
final ThreadContext.ContextStack stack = ThreadContext.getImmutableStack();
ThreadContext.clearStack();
代码示例来源:origin: org.apache.logging.log4j/log4j-core
final String expectedUuidStr = UUID.randomUUID().toString();
ThreadContext.put(tcKey, expectedUuidStr);
ThreadContext.push(expectedUuidStr);
final String expectedExMsg = "This is a test";
try {
代码示例来源:origin: org.apache.logging.log4j/log4j-1.2-api
/**
* Push new diagnostic context information for the current thread.
* <p>
* The contents of the <code>message</code> parameter is
* determined solely by the client.
* </p>
* @param message The new diagnostic context information.
*/
public static void push(final String message) {
org.apache.logging.log4j.ThreadContext.push(message);
}
代码示例来源:origin: org.apache.logging.log4j.adapters/log4j-1.2-api
/**
* Push new diagnostic context information for the current thread.
* <p/>
* <p>The contents of the <code>message</code> parameter is
* determined solely by the client.
*
* @param message The new diagnostic context information.
*/
public static void push(final String message) {
org.apache.logging.log4j.ThreadContext.push(message);
}
代码示例来源:origin: apache/activemq-artemis
@Override
public void pushNdc(String message) {
ThreadContext.push(message);
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
final StringMap contextData = ContextDataFactory.createContextData();
contextData.putValue("A", "B");
ThreadContext.push("first");
final ContextStack contextStack = ThreadContext.getImmutableStack();
final Exception exception = new Exception("test");
different("null contextMap", builder(event).setContextData(null), event);
ThreadContext.push("abc");
final ContextStack contextStack2 = ThreadContext.getImmutableStack();
different("different contextStack", builder(event).setContextStack(contextStack2), event);
代码示例来源:origin: zstackio/zstack
ThreadContext.push(taskUuid);
ThreadContext.push(Platform.getUuid());
内容来源于网络,如有侵权,请联系作者删除!