java.util.logging not outputting to console

Hi,
I'm using idea 10 and having trouble with java.util.logging having switched from log4J.

When I create a logger using:

String loggerName = "com.something";
log = Logger.getLogger(loggerName);
log.addHandler(new ConsoleHandler());
log.setLevel(Level.ALL);
log.fine("just testing");



I get no output in the Idea console when this is run using the JUnit tests.

Can someone tell me what I'm doing wrong?

thanks.
2 comments
Comment actions Permalink

Hi Lawrence,

The problem is that your handler has default log level (INFO).

Change the code as follows and you get output at IJ console:

import java.util.logging.ConsoleHandler;
import java.util.logging.Level;
import java.util.logging.Logger;

public class BrokenAlignment {

    public static void main(String[] args) {
        String loggerName = "com.something";
        Logger log = Logger.getLogger(loggerName);
        ConsoleHandler handler = new ConsoleHandler();
        handler.setLevel(Level.ALL);
        log.addHandler(handler);
        log.setLevel(Level.ALL);
        log.fine("just testing");
    }
}



Regards, Denis

0
Comment actions Permalink

Is there a way to set the console handler at the project level?  Each class generally has it's own Logger so it's not very clean to have to define the console handler on every class you want to use the Logger.

0

Please sign in to leave a comment.