A Logger object is used to emit log messages. Logger does not have a public constructor, but there are several ways to obtain a Logger object to use in your code:

  • Typically, applications call the static getLogger( ) method to create or lookup a named Logger within a hierarchy of named loggers. Loggers have dot-separated hierarchical names, which should be based on the name of the class or package that uses them. Loggers obtained in this way inherit their logging level, resource bundle (for localization), and Handler objects from their ancestors in the hierarchy and, ultimately, from the root Logger defined by the global LogManager.

  • Applets that require a Logger with no security restrictions should use the static getAnonymousLogger( ) method to create an unnamed Logger that is not part of the hierarchy of named Logger objects managed by the LogManager. A Logger created by this method has the LogManager root logger as its parent, and inherits the logging level and handlers of that root logger.

  • Finally, the static field refers to a pre-defined Logger named “global”; programmers may find this pre-defined Logger convenient during the early stages of application development, but it should not be used in production code.

Once a suitable Logger has been obtained, there are a variety of methods that can be used to create a log message:

  • The log( ) methods log a specified message at the specified level, with optional parameters that can be used in message localization. ...

Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.