I'm looking for a way to set the log level for an inner class, let's say I have the following class:
package mypackage;
class Outer {
Inner inner = new Inner();
public void logSomething() {
Logger.getLogger(Outer.class.getName()).log(Level.FINE, "I'm alive!");
inner.logSomething();
}
class Inner {
public void logSomething() {
Logger.getLogger(Inner.class.getName()).log(Level.FINE, "I'm alive too!");
}
}
}
I can set the log level of Outer using the name mypackage.Outer
. But how do I set it for Inner
? I have tested the following without success:
mypackage.Outer
mypackage.Outer.Inner
mypackage.Outer$Inner
(gives an error)mypackage.Inner
Does anyone know if there is a way to do this?
Inner.class.getName()
is returning mypackage.Outer$Inner
which doesn't follow the expected convention for Logger.getLogger() parameter
name
- A name for the logger. This should be a dot-separated name and should normally be based on the package name or class name of the subsystem, such as java.net or javax.swing
You can explicitly use
Logger.getLogger("myPackage.Outer.Inner").log(Level.FINE, "I'm alive too!")
and set the level using myPackage.Outer.Inner
Curiously enough, the message gets formatted by SimpleFormatter()
using $ for inner class as it's outputting class name, not logger name
28-feb-2013 19:04:16 mypackage.Outer$Inner logSomething
FINE: I'm alive too!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With