Why we need two times write handlers in tomcat logging.properties?

To expand on soulcheck's answer, which I didn't understand at first...

The handlers = ... line can be seen as a "variable declaration".

handlers = 1catalina.org.apache.juli.FileHandler, \
       2localhost.org.apache.juli.FileHandler, \
       3manager.org.apache.juli.FileHandler, \
       java.util.logging.ConsoleHandler

"I declare a logger of name 1catalina and type FileHandler, a logger of name 2localhost and type FileHandler.. a logger of type ConsoleHandler (not naming the last one since there's only one, so no ambiguity)."

On the other hand, the .handlers line would be an "assignment".

.handlers = 1catalina.org.apache.juli.FileHandler, 
       java.util.logging.ConsoleHandler

"I assign the 1catalina & console handlers to the root logger. Which means any logging done in the application at all will be forwarded to these handlers (unless overriden)"

The . in .handlers refers to what you're applying that on. In this case, since there's nothing on the left of the ., you're applying it to the root logger, which all loggers inherit from.

But this is exactly the same principle in action in this line:

com.mycompany.MyClass.handlers = java.util.logging.ConsoleHandler

In this case there is something on the left of the . for the .handlers and that means we don't assign these handlers to the root logger but to a specific logger. With this line you say "I'm overwriting the standard logger->handler assignment for this specific logger. In this case, don't act like you would based on the root logger configuration. In this case, I want you to use only the ConsoleHandler for that logger".

So that means that any logging for MyClass will be sent only to the ConsoleHandler and not to any other handler. The other classes are no affected by this line.

Again I'm just repeating the explanation from soulcheck, but in more detail, which I needed myself to understand the difference.


The first line declares the set of handlers that can/will be used, the second one assigns handlers to the specific logger (in this case root logger as .handlers is not prefixed with anything).

Later on in logging.properties each handler is configured.