gpt4 book ai didi

java - ThreadContext.pop() 抛出 NoSuchElementException : The ThreadContext stack is empty in log4j-2. 3

转载 作者:太空宇宙 更新时间:2023-11-04 12:34:52 31 4
gpt4 key购买 nike

我正在尝试从 log4j-1.x 升级到 log4j-2.3 并在运行时出现以下错误。我缺少什么吗?

public void debug(String msg) {
appendContext();
logger.debug(msg);
ThreadContext.pop();
}

[5/25/16 20:08:16:748 SGT] 0000006a ServletWrappe E com.ibm.ws.webcontainer.servlet.ServletWrapper service SRVE0068E: An exception was thrown by one of the service methods of the servlet [MWServlet] in application [DBIN Middleware]. Exception created : [java.util.NoSuchElementException: The ThreadContext stack is empty at org.apache.logging.log4j.spi.DefaultThreadContextStack.pop(DefaultThreadContextStack.java:185) at org.apache.logging.log4j.ThreadContext.pop(ThreadContext.java:391)

最佳答案

我找到了解决方案,我们需要在调用 pop() 之前检查 ThreadContext 是否为空:

public void debug(String msg) {
appendContext();
logger.debug(msg);
if(!ThreadContext.isEmpty()){
ThreadContext.pop();
}
}

关于java - ThreadContext.pop() 抛出 NoSuchElementException : The ThreadContext stack is empty in log4j-2. 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37436945/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com