I have the following problem: I want to use java.util.logging.Logger . No, I found different resources 1 , 2 , 3 , how you can change the behavior of the registrar.
Especially in question 2 a (in my opinion) a good structure is given for initializing registrars according to the class name. It also allows you to modify verbosity at the package level for debugging if necessary.
After a little digging into the problem, I found out that the global registrar and the "empty" registrar (with the name "" ) do not match. See also an example below. I just created a registrar foo.Bar , which is tied to an empty registrar instead of a registrar named foo . Only if I first create a logger bar , the bar.Baz log bar.Baz bound to it correctly.
This makes the approach in this matter mostly useless, since it cannot be assumed that parent registrars should be created earlier. As far as I know, you need to parse the class name and create registrars as needed.
I will correct that I need to add some static {...} code to initialize the registrars in a recursive way before my own log can be initialized? Does this have any negative effect if several classes call the Logger.getLogger(String) method for packet loggers (resulting in the total number of calls in general, for example, both bar.Baz and bar.FooBaz receiving the bar log)?
import java.util.Enumeration; import java.util.logging.LogManager; import java.util.logging.Logger; public class TestLogger { public static void main(String[] args) {
Program exit
'bar': '' 'global': '' 'foo.bar': '' 'bar.baz': 'bar' '': none
source share