我正在尝试记录 Java 应用程序的事件,以根据设置为 ThreadContext 的键来分隔日志文件。但是即使在系统属性中将“log4j2.isThreadContextMapInheritable”设置为“true”之后,我的密钥也没有到达子线程(在 MouseEvent 上创建)。有人请帮我解决这个问题。
我的主要方法:
public class Application {
static {
System.setProperty("log4j2.isThreadContextMapInheritable","true");
}
private final static Logger LOGGER = LogManager.getLogger(Application.class);
public static void main(String[] args) throws Exception
{
ThreadContext.put("cfg","RLS");
LOGGER.info("New window opening!!!"+ThreadContext.get("cfg"));
newWindow();
}
private static void newWindow() throws Exception {
ButtonFrame buttonFrame = new ButtonFrame("Button Demo");
buttonFrame.setSize( 350, 275 );
buttonFrame.setVisible( true );
}
Run Code Online (Sandbox Code Playgroud)
}
ButtonFrame 类:
public class ButtonFrame extends JFrame{
private final static Logger LOGGER = LogManager.getLogger(NewWindow.class);
JButton bChange;
JFrame frame = new JFrame("Our …Run Code Online (Sandbox Code Playgroud)