No, you don't need to do this, but this is an accustomed practice, and a good one. Log4j has been constructed around this assumption in mind, that people will use it this way. It gives you for free the location of the place where a log event was issued, as well as easy administration of log level for the whole branches of loggers.
Theoretically, you could share a logger among multiple classes, or even have only one global; Logger
is thread safe, and it needs to synchronize upon appending object anyway, so your performance would not suffer. You can also name it anything you want, don't need to use the class name. It's not advised, though, for the reason I stated above.
Also, you don't need to make the reference static
, as log4j sees to it that you can only create one logger with a given name, you don't waste memory by having it stored in an instance variable.