2

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?

user837208
  • 2,487
  • 7
  • 37
  • 54
  • See if [this answer](http://stackoverflow.com/a/6315736/418556) solves it for you. – Andrew Thompson Mar 18 '12 at 05:55
  • 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 Mar 18 '12 at 06:10
  • 1
    Err... [`setUseParentHandlers`](http://docs.oracle.com/javase/1.5.0/docs/api/java/util/logging/Logger.html#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 Mar 18 '12 at 06:19
  • 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 accept – user837208 Mar 18 '12 at 06:27

2 Answers2

2

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).

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
1

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.

MrGomez
  • 23,788
  • 45
  • 72