小编rah*_*hna的帖子

log4j2 isThreadContextMapInheritable 属性用法

我正在尝试记录 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)

log4j threadcontext log4j2

3
推荐指数
2
解决办法
3948
查看次数

标签 统计

log4j ×1

log4j2 ×1

threadcontext ×1