ARTICLE AD BOX
.handlers=<handler>
handlers=<handler>
What is the difference between these two configrations. What happend if only "handlers" is configured without ".handler"
I tested, I could see .handlers initialize the specific handler when Logger.getLogger() is invoked.
But when handler alone is used, handler initialization happens when first Logger.log() method is invoked. Kindly help me to understand this case. Thanks in advance.
1
According to the java.util.logging LogManager documentation:
.handlers = Configures handlers specifically for the root logger (obtained via Logger.getLogger(""))
handlers = Specifies handlers created globally and added to the root logger at LogManager initialization
Your observations are correct:
# Lazy initialization - handlers created when Logger.getLogger() is invoked .handlers=java.util.logging.ConsoleHandler # Eager initialization - handlers created at LogManager startup (not at log() time) handlers=java.util.logging.ConsoleHandlerWhat happens if only handlers is configured without .handlers?
The handlers property creates and attaches handlers to the root logger during LogManager initialization (when the JVM starts or when the config file is first read). All loggers that inherit from the root will use these handlers.
For me, I think it's better to use handlers for global configuration and use .handlers only if you need different behavior for the root logger specifically.
Explore related questions
See similar questions with these tags.
