Prev: Free Online Subversion Training - Introduction to Subversion for Developers
Next: Applet, file & resource
From: Rhino on 29 Apr 2010 20:50 I need to get something straight about parent loggers in java.util.logging. I'll skip the lengthy preamble about how I got to this point and just get straight to the question. Let's say that I set up two loggers: - a "master" logger on org.sscce with level set to WARNING and a file handler writing to master.log.xml - a "project" logger on org.sscce.baz3 with level set to ALL and a file handler writing to baz3.log.xml Am I right in understanding that all records written to the project logger will ALWAYS be written to the master logger as well REGARDLESS of which level the log records are? In other words, if I write a FINEST log record to the project logger, a copy of that record will ALWAYS be written to BOTH baz3.long.xml AND master.log.xml, even though the master logger is set to only allow WARNING and SEVERE records? My reading of various documents about logging had left me with the impression that simply setting the level on the master logger would be enough to screen out records that had a lower level but my experiments show that this is NOT the case at all; the level of the project logger (and even adding a Filter directly to the master logger) screen out no records whatever! (The level of the logger WILL stop records that are written directly to that logger but not ones passed from deeper in the hierarchy.) I tried putting a Filter that only accepts WARNING and SEVERE records on both the master logger and the master logger's FileHandler and those filters don't keep ANYTHING out. Basically, I was thinking of setting up a situation where a project logger wrote all levels of messages to its log file but a master logger only gets messages that are WARNING and SEVERE; basically the master log file would only advise its user about the major issues and none of the lesser ones. If the Filter on the FileHandler of the master logger will not make that happen, I suppose I will just use XSL to write reports showing only the WARNING and SEVERE events and not bother with the master logger at all. Assuming I just haven't written the code incorrectly, I'm not sure where a hierarchy of loggers would be helpful at all based on what I've seen. Can someone clue me in on that? Is the behaviour I'm getting in my code, as described above, consistent with what I SHOULD be getting? It's not what I was expecting from the documents but perhaps I just misunderstood what they were trying to say. -- Rhino
From: markspace on 29 Apr 2010 22:09 Rhino wrote: > Am I right in understanding that all records written to the project > logger will ALWAYS be written to the master logger as well REGARDLESS of > which level the log records are? I think the answer is yes. Loggers always pass up their log records to their parent, unless useParentHandler() is set to false. A little experimentation would clear this up. > my experiments > show that this is NOT the case at all; the level of the project logger > (and even adding a Filter directly to the master logger) screen out no > records whatever! This seems wrong. Can you verify that the log messages you see are not coming from some other logger in the system? I've found this to be a common problem with configuring Java logging. You think you've configure a logger but really some other logger is messing you up. > I tried putting a Filter that only accepts WARNING and SEVERE records on > both the master logger and the master logger's FileHandler and those > filters don't keep ANYTHING out. This says to me "look at a different logger." > > Basically, I was thinking of setting up a situation where a project > logger wrote all levels of messages to its log file but a master logger > only gets messages that are WARNING and SEVERE; basically the master log > file would only advise its user about the major issues and none of the > lesser ones. This should work, I'm certain I've done exactly that. If you continue to have problems, I'll try to test it for you. Can you make an SSCCE for us?
From: markspace on 30 Apr 2010 12:42 markspace wrote: > I did make at least one mistake: loggers do NOT pass log messages to > their parent if their log level is set higher than the log message's level: Post scriptum: I was thinking about this and I realized that child loggers also normally inherit their parent's log level. So the normal case is that all messages logged by the parent would be passed along by all of the children. This might explain the perception that loggers always pass up their messages to their parent. By default, the log levels are set to allow that to happen.
From: Rhino on 30 Apr 2010 16:06 On Apr 30, 12:42 pm, markspace <nos...(a)nowhere.com> wrote: > markspace wrote: > > I did make at least one mistake: loggers do NOT pass log messages to > > their parent if their log level is set higher than the log message's level: > > Post scriptum: I was thinking about this and I realized that child > loggers also normally inherit their parent's log level. So the normal > case is that all messages logged by the parent would be passed along by > all of the children. > But I would never log to the parent directly would I? Isn't a parent just the ultimate repository of the most important (however you define important in individual cases) messages from the child logs? Or am I looking at everything upside down? I had thought the child was supposed to have all the gory details with only the most important records passed to the parent. Maybe I've got that wrong and the parent is going to have much more and the child logs only get the most important records.... > This might explain the perception that loggers always pass up their > messages to their parent. By default, the log levels are set to allow > that to happen. I'll mull that over as I work through the variations in your test program. Thanks for your help with this; I'll post back in a couple of hours once I've tried a bunch of things. -- Rhino
From: markspace on 30 Apr 2010 17:57 Rhino wrote: > But I would never log to the parent directly would I? Probably not, but you might configure a parent for logging. If you have several packages you want to debug, it's easier to log with their common name (the parent) rather than configure each one individually. For example, if you wanted to get log messages from all of Swing, set the parent ("javax.swing") to an appropriate log level and add a handler. Easier than trying to set each class individually (the children).
|
Next
|
Last
Pages: 1 2 Prev: Free Online Subversion Training - Introduction to Subversion for Developers Next: Applet, file & resource |