Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

logging static methods in a parent class

Tags:

java

static

log4j

I have an abstract class Parent, with 2 subclasses A and B. Parent has one static method called do(). I am wondering if there is a way for that static method to add log info in Logger for class A when it's called as A.do() and log B when it's called as B.do(). The usual

protected final Logger LOGGER = Logger.getLogger(getClass());

won't work as do() is a static method so Logger needs to be static as well, but the getClass() method is obviously not static.

Thanks.

like image 764
sakis kaliakoudas Avatar asked Jun 01 '26 08:06

sakis kaliakoudas


1 Answers

private final static Logger LOGGER = Logger.getLogger(A.class);

Every class having its own logger: specifying the class is fine.

like image 196
Bruno Grieder Avatar answered Jun 03 '26 20:06

Bruno Grieder



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!