To prevent log records being forwarded to the logger’s parent handlers we can set false
the useParentHandlers
field using the Logger.setUserParentHandlers(boolean useParentHandlers)
method.
package org.kodejava.util.logging;
import java.util.logging.Logger;
import java.util.logging.ConsoleHandler;
public class NoParentLogger {
public static void main(String[] args) {
Logger logger = Logger.getLogger(NoParentLogger.class.getName());
// Do not forward any log messages the logger parent handlers.
logger.setUseParentHandlers(false);
// Specify a ConsoleHandler for this logger instance.
logger.addHandler(new ConsoleHandler());
logger.info("Logging an information message.");
}
}
Latest posts by Wayan (see all)
- How do I get number of each day for a certain month in Java? - September 8, 2024
- How do I get operating system process information using ProcessHandle? - July 22, 2024
- How do I sum a BigDecimal property of a list of objects using Java Stream API? - July 22, 2024