2
votes

I've setup (logger class constructor) logging as below-

 Log() {


        loggerObj = Logger.getLogger("");

        //Create console handler and set its level and then setup its formatter 
        handler = new ConsoleHandler();
        handler.setLevel(Level.FINEST);
        formatter = new LogFormatter();
        handler.setFormatter(formatter);

        //assign handler to logger objs
        loggerObj.setUseParentHandlers(false);
        loggerObj.addHandler(handler);

    }

Members of the Log class are-

    static Logger loggerObj;
    ConsoleHandler handler;
    LogFormatter formatter;

Even though I've setup level to be FINEST and setUseParentHandlers to false, why is that I am not able to log anything below INFO?

EDIT- As per comment- After I modified the global logging.properties file and set level to ALL, it worked. So I think my question is why setUseParentHandlers isn't working?

2
See if this answer solves it for you.Andrew Thompson
After I modified the global logging.properties file and set level to ALL, it worked. So I think my question is why setUseParentHandlers isn't working?user837208
Err... setUseParentHandlers specifies whether to send data recursively up the tree. Unless you explicitly don't want log messages to propagate to loggers that parent this one, that command shouldn't have any bearing on how your loggers behave in the context of a single log level specification. Perhaps I don't understand what you're asking for here?MrGomez
Damn! setUseParentHandlers was just too intutive that I assumed that it will set whether to use parent handler or not. @MrGomez please post this as answer and I will acceptuser837208
@user837208 Done. Glad to help!MrGomez

2 Answers

2
votes

So I think my question is why setUseParentHandlers isn't working?

There is no evidence that setUseParentHandlers is NOT working.

Rather, what appears to be happening is that your Logger is (was) being created with the default level of INFO. Try setting it by hand by calling Logger.setLevel(FINEST).

1
votes

As mentioned in the errata, setUseParentHandlers specifies whether to send data recursively up the logging tree. Unless you explicitly don't want log messages to propagate to loggers that parent this one, that command shouldn't have any bearing on how they behave in the context of a single invocation.