lundi 7 septembre 2015

Motivation for Java Logging Customs

I've been reading up on logging in Java and it seems like SLF4J is the way to go.

What I don't understand is why the logging object is obtained/initialized the way it is.

Why does

private static final Logger logger = LoggerFactory.getLogger(App.class);

need to be in every class?

  1. Why not instead have just some static logger instance for all classes/class-instances? (What happens if I don't create new instances for every class?)

  2. Why do I need to pass the class object of the class the logger is being used in to the factory? Won't the logger have all of these details during runtime anyway? (What happens if I pass some different class object?)

Aucun commentaire:

Enregistrer un commentaire