我看到一个相当奇怪的问题。
我创建了一些标准的 Java 记录器(使用 Logger.getLogger()、FileHandle 和 SimpleFormatter。)它们工作正常,并按预期输出日志文件。
然后,我使用了 Gigaspaces API 中的一些类(com.gigaspaces.gs-openspaces - 通过 Maven 依赖项包含),其中包括自己的日志记录。之后,我的记录器的所有输出最终都在 Gigaspaces 日志文件中(例如 ~/.m2/repository/com/gigaspaces/logs/2017-03-27~12.46-gigaspaces-service-135.60.146.142-23534。 log) 而不是在他们应该使用的适当的日志文件中。
如果我在初始化 Gigaspaces 后创建更多记录器,这些新记录器将按预期工作。只有在初始化 gigaspace 之前创建的记录器会受到影响。
我试着在 Gigaspaces 的代码中四处寻找,那里有很多代码。我没有立即看到任何明显的东西。
我在设置记录器时做错了吗?库可以窃取与其类无关的预先存在的记录器的输出似乎是不对的。
下面的简短测试程序演示了这个问题:
Logger testLog = Logger.getLogger("testlog");
try {
FileHandler fh = new FileHandler("testlog.log");
fh.setFormatter(new SimpleFormatter());
testLog.addHandler(fh);
}
catch (Exception e) {
// Not important
e.printStackTrace();
}
testLog.log(Level.INFO, "This appears in the main log file");
// Spin up gigaspaces, even by trying to connect to a space that doesn't exist
UrlSpaceConfigurer testSpaceConfigurer = new UrlSpaceConfigurer("jini://*/*/testSpace?locators=127.0.01").lookupTimeout(1);
try {
GigaSpace g = new GigaSpaceConfigurer(testSpaceConfigurer).gigaSpace();
}
catch (Exception e) {
// This will throw an exception, just ignore it.
}
testSpaceConfigurer.close();
testLog.log(Level.INFO, "This appears in the (wrong) gigaspaces log file");