am using log4j for logging, in order to get the class name of the of the respective methods while executing, i got some common method which uses SecurityManager to get the class name, but i dont want to use SecurityManager, is their any other way to get the class name during runtime. Also i dont want to write the code(MyClass.getClassName
) to get the classname in each and every class.
class log extends SecurityManager {
public String getClassName() {
return getClassContext()[3].getName();
}
}
Solution for static logger:
private static final Logger LOG = Logger.getLogger(new Object() { }.getClass().getEnclosingClass());
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