mercredi 18 novembre 2015

LoggerFactory.getLogger(ClassName.class) vs LoggerFactory.getLogger(this.getClass().getName())

I'm trying to improve my optimization skills in Java. In order to achieve that, I've got an old program I made and I'm trying my best to make it better. In this program I'm using SL4J for logging. To get the logger I did:

Logger logger = LoggerFactory.getLogger(this.getClass().getName());

At the time I wrote the code, I thought this was the best option, because I remove a reference to the class name(which may be refactored). But now I'm not so sure anymore...

Logger logger = LoggerFactory.getLogger(ClassName.class);

On the other side, keeps the reference to the class name, but it removes one method call. This may not be a big improvement in performance for one class, but when you have lots of class, this may be something.

So my question is:

Which approach is better? Using the class name or getting it through reflection?

Please, motivate your answer with pro and cons. Thank you.





Aucun commentaire:

Enregistrer un commentaire