Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In java.util.logging, what is the global logger for?

In the java.util.logging logging framework there's a special Logger instance named "global", but I can't find any documentation of what its intended use is. The documentation for Logger.getGlobal() just says

Return global logger object with the name Logger.GLOBAL_LOGGER_NAME.

Logger.GLOBAL_LOGGER_NAME, in turn, is documented only as

GLOBAL_LOGGER_NAME is a name for the global logger.

My fairly extensive searches didn't turn up any more useful documentation.

What is the global logger intended to be used for? Is that documented somewhere that I missed?

like image 653
Sam Hanes Avatar asked Dec 20 '22 21:12

Sam Hanes


1 Answers

The "global" Logger object is provided as a convenience to developers who are making casual use of the Logging package. Developers who are making serious use of the logging package (for example in products) should create and use their own Logger objects, with appropriate names, so that logging can be controlled on a suitable per-Logger granularity. Developers also need to keep a strong reference to their Logger objects to prevent them from being garbage collected.

From here (don't look at the fact that the field is deprecated, I just wanted to point you to a valid explanation).

Normally, when enabling logging in an application, you define more granular loggers, usually per Java packages or classes.

If you do not want to do that, you can use this global logger, which will handle all logging statements, no matter the library, package or class they are contained in.

like image 114
Andrei Nicusan Avatar answered Jan 09 '23 09:01

Andrei Nicusan