Frage

I am trying to create a Logger using Java's utility "Logger". It seems to work fine but when I create the logger it prints this to the log file:

[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

I am not sure what is causing that error. For reference this is how I create my 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) {}
}

Any help/ideas would be great.

War es hilfreich?

Lösung

The Logger.getLogger("") call means you are using the root logger. When you set the root logger level to FINE that is setting the effective level for all child loggers too. These child loggers are the ones generating the 'errors'. As suggested by 's106mo', you have to set the level of your logger namespace if you only want to see your messages.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top