Is it possible to make log4j display which file it used to configure itself?

后端 未结 3 1912
清酒与你
清酒与你 2020-12-07 17:41

Question

Is it possible to make Log4J display the full path of the file it used for configuration?


Background

I have a

3条回答
  •  一向
    一向 (楼主)
    2020-12-07 17:51

    I am using Log4J2 and if you want to get the file from inside your Java Program this worked for me:

    LoggerContext lContect = LogManager.getContext();
    Field f = lContect.getClass().getDeclaredField("configuration");
    f.setAccessible(true);
    XmlConfiguration iWantThis = (XmlConfiguration) f.get(lContect);
    System.out.println("Config File: " + iWantThis.getName());
    

提交回复
热议问题