Loggers are used to log records to certain outputs, including file, console, etc. They use various handlers to actually do the output-dependent operations.
Client applications can get named loggers by calling the methods getLogger
. They can also get anonymous loggers by calling the methods getAnonymousLogger
. Named loggers are organized in a namespace hierarchy managed by a log manager. The naming convention is usually the same as java package's naming convention, i.e., using dot-separated strings. Anonymous loggers do not belong to any namespace.
Loggers "inherit" log level setting from their parent if its own level is set to null
. This is also true for the resource bundle. The logger's resource bundle is used to localize the log messages if no resource bundle name is given when a log method is called. If getUseParentHandlers
is true
, loggers also inherit their parent's handlers. Here "inherit" only means the "behaviors" are inherited. The internal fields value will not change, for example, getLevel()
still returns null
.
When loading a given resource bundle, the logger first tries to use the context classloader. If that fails, it tries the system classloader. And if that still fails, it searches up the class stack and uses each class's classloader to try to locate the resource bundle.
Some log methods accept log requests that do not specify the source class and source method. In these cases, the logging framework will automatically infer the calling class and method, but not guaranteed to be accurate.
Once a LogRecord
object has been passed into the logging framework, it is owned by the logging framework and the client applications should not use it any longer.
All methods of this class are thread-safe.
@see LogManager