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
}
我们如何选择我们想要记录的日志文件?