I want to add logging to quite few classes in my program. Do I need to add lines to define a logger to each class that needs a logger (I want to avoid passing logger object around my program.
public class SomeClass {
static Logger logger = Logger.getLogger(SomeClass.class);
.......
If I do this, can I get this call to “know” its class (something like this.class
Or are there alternative ways of doing this
Yes you need to add lines to each class.
If your logger is static (as is your example) you need to specify the class each time like you did (SomeClass.class). If you make your logger non-static then you can use this.getClass() which would be more cut-n-paste friendly: