Logger getAnonymousLogger() Method in Java with Examples Last Updated : 24 Apr, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report The getAnonymousLogger() method of a Logger class used to create an anonymous Logger. There are two types of getAnonymousLogger() method depending upon no of the parameter passed. getAnonymousLogger(): This method is used to create an anonymous Logger. This newly created anonymous Logger is not registered in the LogManager namespace and no access checks on updates to the logger. So the question is why we need this logger if there are no access checks because the factory method is primarily intended for use from applets. Because the resulting Logger is anonymous it can be kept private by the creating class. This removes the need for normal security checks, which in turn allows untrusted applet code to update the control state of the Logger. For example, an applet can do a setLevel or an addHandler on an anonymous Logger. This logger is configured to have the root logger ("") as its parent. It inherits its effective level and handlers from the root logger. Changing its parent via the setParent method will still require the security permission specified by that method. Syntax: public static Logger getAnonymousLogger() Parameters: This method accepts nothing Return value: This method returns a newly created private Logger. Below programs illustrate getAnonymousLogger(java.lang.String) method: Program 1: Java // Java program to demonstrate // Logger.getAnonymousLogger() method import java.util.logging.*; public class GFG { public static void main(String[] args) { // Create a Logger with class name GFG Logger logger = Logger.getAnonymousLogger(); // Call info method logger.info("Message 1"); logger.info("Message 2"); } } The output printed on console is shown below. Output: Program 2: Java // Java program to demonstrate Exception thrown by // Logger.getAnonymousLogger(java.lang.String) method import java.util.logging.*; public class GFG { public static void main(String[] args) { String LoggerName = null; // Create a Logger with a null value try { Logger logger = Logger .getAnonymousLogger(LoggerName); } catch (NullPointerException e) { System.out.println("Exception Thrown :" + e); } } } The output printed on console is shown below. Output: getAnonymousLogger(String resourceBundleName): This method is used to create an anonymous Logger. This newly created anonymous Logger is not registered in the LogManager namespace and no access checks on updates to the logger. This Logger has ResourceBundle passed as a parameter to be used for localizing messages for this logger. Syntax: public static Logger getAnonymousLogger(String resourceBundleName) Parameters: This method accepts single Parameter resourceBundleName which is the name of ResourceBundle to be used for localizing messages for this logger. Return value: This method returns a suitable Logger. Exception: This method will throw MissingResourceException: if the resourceBundleName is non-null and no corresponding resource can be found. Below programs illustrate getAnonymousLogger(String resourceBundleName) method: Program 1: Java // Java program to demonstrate // getAnonymousLogger(String resourceBundleName) method import java.util.ResourceBundle; import java.util.logging.*; public class GFG { public static void main(String[] args) { // Create ResourceBundle using getBundle // myResource is a properties file ResourceBundle bundle = ResourceBundle .getBundle("resourceBundle"); // Create a Logger with resourceBundle Logger logger = Logger .getAnonymousLogger( bundle.getBaseBundleName()); // Log the info logger.info("Message 1 for logger"); logger.info("Message 1 for logger"); } } For the above program, there is a properties file name resourceBundle. we have to add this file alongside the class to execute the program. References: https://docs.oracle.com/javase/10/docs/api/java/util/logging/Logger.html#getAnonymousLogger() https://docs.oracle.com/javase/10/docs/api/java/util/logging/Logger.html#getAnonymousLogger(java.lang.String) Comment More infoAdvertise with us Next Article Logger getAnonymousLogger() Method in Java with Examples A AmanSingh2210 Follow Improve Article Tags : Java Java - util package Java-Functions Java-Logger Practice Tags : Java Similar Reads Logger getLogger() Method in Java with Examples The getLogger() method of a Logger class used find or create a logger. If there is a logger exists with the passed name then the method will return that logger else method will create a new logger with that name and return it. There are two types of getLogger() method depending upon no of the parame 4 min read Logger getHandler() Method in Java with Examples The getHandlers() method of the Logger class is used to get the Handlers linked with this logger. Handler is used to taking care of the actual logging. one or more Handler can be added to a Logger. When messages are logged via the Logger, the messages are forwarded to the Handler. This method is hel 2 min read 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 ge 2 min read Logger getName() Method in Java with Examples getName() method of a Logger class used to get the name of logger. Many times you have to check the logger name so we can use this method to get the logger name. Syntax: public String getName() Parameters: This method accepts nothing. Return value: This method return logger name and it will be null 1 min read Logger getFilter() Method in Java with Examples The getFilter() method of the Logger class is used to get the current filter for this Logger instance. A Filter is useful to filter out log messages. we can say that filter decide the message gets logged or not. Filters are represented by the Java interface java.util.logging.Filter Syntax: public Fi 2 min read Like