[slf4j-user] best practice for naming loggers?
Rusty Wright
rwright.lists at gmail.com
Mon Mar 21 00:34:34 CET 2011
In the log4j documentation they recommend "statically instantiating a logger in each class, with the logger name equal to the fully qualified name of the class." For example,
static Logger logger = Logger.getLogger(MyApp.class);
I've never understood why it's necessary to declare the logger static. I've assumed/guessed that it is to reduce the number of calls to getLogger.
The slf4j documentation doesn't use static; for example,
final Logger logger = LoggerFactory.getLogger(Wombat.class);
I've also wondered why everyone uses .class; I've been using this.getClass(); for example,
private final transient Logger log = LoggerFactory.getLogger(this.getClass());
The advantage of that is that you never have to worry about changing that line; you can copy and paste it everywhere, and set up eclipse to automatically put that line in when you create a new class.
The reason I ask is that I read the article by Michael Glauche, "Logging with SLF4J and Guice", at http://glauche.de/2009/08/24/ and I don't see an advantage of his method over using this.getClass().
Using this.getClass() has worked for me, unless I need to use the logger in a static method, so I'm wondering if there is something I'm overlooking.
Thanks
--
0x2B | ~0x2b -- Hamlet
More information about the slf4j-user
mailing list