Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SLF4j - logback question: how many logger objects should you create?

I am just starting to use logback and I have a question:

Should you create one logger for each class like the following:

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

Or is that too much? maybe create a logger one per package? what is the generally considered good practice? thanks.

like image 999
neo Avatar asked May 16 '11 16:05

neo


1 Answers

One (private one) per class - the overhead is low and you get the source information (which logger printed this) for free.

Occasionally it's worth creating an additional logger for an inner class if you want to setup your log configuration to report them at different levels.

like image 54
Matt Avatar answered Oct 13 '22 05:10

Matt