LogManager getLogger() method in Java with Examples

The getLogger() method of java.util.logging.LogManager is used to get the specified Logger in this LogManager instance. This Logger must be a named Logger. This method will get this Logger in this LogManager if it exists. If it does not exists, then this method returns null.
Syntax:
public Logger getLogger(Logger logger)
Parameters: This method accepts a parameter logger which is the name of the Logger to be get in this LogManager instance.
Return Value: This method returns the name of this Logger in this LogManager if it exists. If it does not exists, then this method returns null.
Below programs illustrate getLogger() method:
// Java program to illustrate// LogManager getLogger() method import java.util.logging.*;import java.util.*; public class GFG { public static void main(String[] args) { // Create LogManager object LogManager logManager = LogManager.getLogManager(); String LoggerName = "GFG"; Logger logger = Logger.getLogger(LoggerName); logManager.addLogger(logger); System.out.println("\nList of Logger Names: "); Enumeration<String> listOfNames = logManager.getLoggerNames(); while (listOfNames.hasMoreElements()) System.out.println(listOfNames.nextElement()); System.out.println( "\nGet Logger Name " + LoggerName + ": " + logManager.getLogger(LoggerName)); LoggerName = "Geeks"; System.out.println( "\nGet Logger Name " + LoggerName + ": " + logManager.getLogger(LoggerName)); }} |
Output:
List of Logger Names: GFG global Get Logger Name GFG: java.util.logging.Logger@1540e19d Get Logger Name Geeks: null

Logger getLogger() Method in Java with Examples

LogManager checkAccess() method in Java with Examples

LogManager reset() method in Java with Examples

LogManager getLogManager() method in Java with Examples

LogManager getLoggerNames() method in Java with Examples

LogManager addLogger() method in Java with Examples

LogManager getProperty() method in Java with Examples

LogManager readConfiguration() method in Java with Examples

Java.util.Collections.rotate() Method in Java with Examples

Java.util.Collections.disjoint() Method in java with Examples




Please Login to comment…