0
我們正在製作一個由多個嵌入罐組成的程序。每個jar需要一個單獨的日誌文件。問題是,當我們試圖登錄核心jar文件時,日誌消息被寫入其他jar的日誌文件中。Log4j2針對不同罐子的不同日誌
這是核心jar文件的代碼。
static Logger logCore = LogManager.getLogger(); //log file created
public static void main(String[] args)
{
LoggerContext context = (org.apache.logging.log4j.core.LoggerContext) LogManager.getContext(false);
org.apache.logging.log4j.core.selector.BasicContextSelector
File file = new File("/home/pi/NetBeansProjects/CoreService/dist/log4j2.xml");
context.setConfigLocation(file.toURI());
logCore.info("Core Service initiated"); //Log here is done in the lof od the Core jar as expected
//Run methods of another jar (DBcontrollers)
try
{
SmartBoxSN = DBControllers.DeviceSetupController.GetOwnDeviceSetupFieldNameID(3).Value;
}
catch(SQLException | ClassNotFoundException ex)
{
}
logCore.info("Core Service initiated"); //Log here is wrongly done in the log file of DBControllers
}
我們如何選擇我們想要記錄的日誌文件?