我正在尝试使用Java的实用程序“Logger”创建一个Logger。它似乎工作正常,但是当我创建记录器时,它将其打印到日志文件:
[CONFIG 2013-12-09 13:19:16]Running in a non-OSGi environment
[CONFIG 2013-12-09 13:19:16]"Using default requesting executor [java.util.concurrent.ThreadPoolExecutor@77fe4169]."
[CONFIG 2013-12-09 13:19:16]"Using default responding executor [com.google.common.util.concurrent.MoreExecutors$SameThreadExecutorService@30dc9065]."
[FINE 2013-12-09 13:19:16]USING LTQ class:{0}
[FINE 2013-12-09 13:19:17]Trying to locate com/proj1/proj/jaxb.properties
[FINE 2013-12-09 13:19:17] not found
[FINE 2013-12-09 13:19:17]Checking system property javax.xml.bind.JAXBContext
[FINE 2013-12-09 13:19:17] not found
[FINE 2013-12-09 13:19:17]Checking META-INF/services
[FINE 2013-12-09 13:19:17]Unable to find: META-INF/services/javax.xml.bind.JAXBContext
[FINE 2013-12-09 13:19:17]Trying to create the platform default provider
[FINE 2013-12-09 13:19:17]Trying to load com.sun.xml.internal.bind.v2.ContextFactory
[FINE 2013-12-09 13:19:17]loaded com.sun.xml.internal.bind.v2.ContextFactory from jar:file:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar!/com/sun/xml/internal/bind/v2/ContextFactory.class
[FINE 2013-12-09 13:19:17]Property com.sun.xml.internal.bind.XmlAccessorFactoryis not active. Using JAXB's implementation
我不确定导致该错误的原因。作为参考,这是我创建Logger的方式:
protected File file;
protected Logger logger = Logger.getLogger("");
public MyLogger(String instanceName) {
logger.setLevel(Level.FINE);
String filePath = "mylog_trace" + instanceName;
file = new File(filePath);
try {
FileHandler fileHandler = new FileHandler(filePath, 5242880, 5, true);
fileHandler.setFormatter(new java.util.logging.Formatter() {
@Override
public String format(LogRecord logRecord) {
return "[" + logRecord.getLevel() + " " + createDateTimeLog() + "]" + logRecord.getMessage() + "\r\n";
}
});
logger.addHandler(fileHandler);
} catch (IOException e) {}
}
任何帮助/想法都会很棒。
答案 0 :(得分:0)
Logger.getLogger("")
调用意味着您正在使用根记录器。将根记录器级别设置为FINE
时,也为所有子记录器设置effective level。这些儿童记录器是产生“错误”的记录器。根据's106mo'的建议,如果您只想查看邮件,则必须设置记录器命名空间的级别。