From java.util.logging.Logger:
Logger names can be arbitrary strings, but they should normally be based on the package name or class name of the logged component, such as java.net or javax.swing
Could anyone explain this sentence to me ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
“Logger names can be arbitrary strings …”:
Any code that wants the same logger instance just has to specify the same logger name (good luck spelling “supercalifragilisticexpialidocious” the same way twice).
However, you might want to share loggers more easily, get a handle to a specific class’ logger for configuration, or have a hierachical relationship between loggers (e.g. organize loggers to into parents and children). Classes and packages are already organized hierarchically, so they recommend that logger names:
“… should normally be based on the package name or class name of the logged component …”
Now I can easily get a handle to any logger for any class from anywhere (I just need to know its fully qualified class name). Also, now the the Logger framework can see which loggers are related to which, e.g. that the logger for “com.example.stackoverflow” is the parent of the logger for “com.example.stackoverflow.Foo”.
But what if the package name changes or your class name changes? This code below does exactly the same thing as the code above, but in a less redundant and more maintainable manner:
Now if the package changes, the logger name is handled automatically. If the class is renamed in an IDE, the IDE will likely notice the
Foo.classliteral in thegetLoggercall above and update theFoo.classliteral accordingly.