Java Logging: LogManager

The java.util.logging.LogManager manages the internal Logger hierarchy, and initiates the configuration of the Logger‘s, either through the configuration class or configuration file.

There is only a single LogManager instantiated in the whole JVM. It is a singleton, in other words. Here is how to obtain the LogManager instance:

LogManager manager = LogManager.getLogManager();

  

You will not often need to interact directly with the LogManager, except for a few borderline cases.

For instance, if you want to reload the configuration file, you can do so using either of these methods:

readConfiguration();

readConfiguration(inputStream);

  

The first method on the LogManager simply re-reads the configuration from file (or class), in case these has changed.

The second method on the LogManager simply reads the configuration from the given InputStream.

You can also get access to an MXBean (Java Management Extensions) from the LogManager using the methodgetLoggingMXBean(). Here is an example:

LoggingMXBean mxBean = logManager.getLoggingMXBean();

  

The LogManager has more methods than these two, but most often you will not need them. Check the official JavaDoc for more information, if you need to do something not covered here.

时间: 2024-10-05 18:23:36

Java Logging: LogManager的相关文章

Java Logging: Logger Hierarchy

Table of Contents Filters and Handlers in the Logger Hierarchy Log Levels of Loggers in the Hierarchy The Logger's used in your application are typically organized into a hierarchy, as mentioned elsewhere in this tutorial. This text will take a close

Java Logging: Overview

Table of Contents Log Level Logger Hierarchy LogManager In this text I will try to give you an overview of the java.util.logging API. Hopefully it will be easier to understand the individual components once you understand the big picture. Many of the

Java Logging: Configuration

Table of Contents Configuration Class Configuration File The Java Logging API can be configured in two ways: Via a configuration class. Via a configuration file. The initialization of the configuration is taken care of by the java.util.logging.LogMan

Java Logging API - Tutorial

Java Logging This article describes how to use the Logging API in Java programs. It includes an example for creating an HTML logger. Table of Contents 1. Overview 1.1. Logging 1.2. Logging in Java 1.3. Create a logger 1.4. Level 1.5. Handler 1.6. For

Java Logging: Formatters

The Handler's in the Java Logging API use a java.util.logging.Formatter to format theLogRecord's before writing it to an external system. Java comes with two built-in Formatter's (subclasses of Formatter): SimpleFormatter XMLFormatter The various Han

Java Logging: Logger

Table of Contents Logging Messages The log() Methods The logp() Methods The logrb() Methods The Last Log Methods Adding and Removing Handlers Setting a Log Filter Setting the Log Level Parent Logger Additional Methods The java.util.Logger class is th

Java Logging: Handlers

Table of Contents Handlers and Formatters Built-in Handlers ConsoleHandler FileHandler File Name Pattern StreamHandler SocketHandler MemoryHandler A Handler is a component that takes care of the actual logging to the outside world. You can add one or

Java Logging: Log Levels

Table of Contents Filtering Messages When a message is logged via a Logger it is logged with a certain log level. The built-in log levels are: SEVERE WARNING INFO CONFIG FINE FINER FINEST The log level is represented by the class java.util.logging.Le

Java Logging: Filters

You can set a Filter on a Logger. A Filter can filter out log messages, meaning decide if the message gets logged or not. Filters are represented by the Java interface java.util.logging.Filter Here is an example of setting a Filter on a Logger: Filte