SLF4J Java Logging Design

java, logging, slf4j

Solution

The result of this is that each logging statement generated by that logger contains the name of the class. You want to do this to:

- identify the source of that logging message in the output

- filter effectively on those messages. You can enable disable messages by class and/or the containing package. e.g. you may wish to disable all your DAO package messages (for whatever reason)

The above is a very common pattern in logging. Note however that you don't just have to provide a class, but you can provide your own string instead, and thus arbitrarily categorise your messages yourself.

Problem

I am beginning to use SLF4J for logging and the first thing that strikes to me is the following piece of code ``` public class MyClass { private static final logger = org.slf4j.LoggerFactory.getLogger(MyClass.class) } ``` What is the design principle or logic of using the class as an argument to obtain an instance of the logger ?

Original source