Logger entering() method in Java with Examples Last Updated : 28 Mar, 2019 Comments Improve Suggest changes Like Article Like Report The entering() method of a Logger class used to Log a method entry. There are three types of entering() method depending upon the parameters passed. entering(String sourceClass, String sourceMethod): This method is used to Log a method entry.Actually many times in application development we need to log when we enter in a method of class so this is a convenience method that can be used to log entry to a method. This method logs with message "ENTRY", log level FINER, and the given sourceMethod and sourceClass are also logged. Syntax: public void entering(String sourceClass, String sourceMethod) Parameters: This method accepts two parameters: sourceClass is the name of the class that issued the logging request and sourceMethod is the name of the method that is being entered. Return value: This method returns nothing. Below program illustrate entering(String sourceClass, String sourceMethod) method: Program 1: Java // Java program to demonstrate // entering(String, String) method import java.io.IOException; import java.util.List; import java.util.logging.*; public class GFG { public static void main(String[] args) throws SecurityException, IOException { // Create a Logger Logger logger = Logger.getLogger( GFG.class.getName()); // Create a file handler object FileHandler handler = new FileHandler("logs.txt"); handler.setFormatter(new SimpleFormatter()); // Add file handler as // handler of logs logger.addHandler(handler); // set Logger level() logger.setLevel(Level.FINER); // call entering methods with class // name = GFG and method name = main logger.entering(GFG.class.getName(), "main"); // calling again for List class toString() logger.entering(List.class.getName(), "toString()"); } } The output printed on log.txg file is shown below. Output: entering(String sourceClass, String sourceMethod, Object param1): This method is used to Log a method entry, with one parameter where parameter passed is an object we want to log. Actually many times in application development we need to log when we enter in a method of class so this is a convenience method that can be used to log entry to a method. This method logs with message "ENTRY {0}", log level FINER, and the given sourceMethod, sourceClass, and parameter are logged. Syntax: public void entering(String sourceClass, String sourceMethod, Object param1) Parameters: This method accepts three parameters: sourceClass is the name of the class that issued the logging request and sourceMethod is the name of the method that is being entered. param1: is the parameter to the method being entered. Return value: This method returns nothing. Below programs illustrate entering(String sourceClass, String sourceMethod, Object param1) method: Program 1: Java // Java program to demonstrate // entering(String, String, Object) method import java.io.IOException; import java.util.logging.*; public class GFG { public static void main(String[] args) throws SecurityException, IOException { // Create a Logger Logger logger = Logger.getLogger( GFG.class.getName()); // Create a file handler object FileHandler handler = new FileHandler("logs.txt"); handler.setFormatter(new SimpleFormatter()); // Add file handler as // handler of logs logger.addHandler(handler); // set Logger level() logger.setLevel(Level.FINER); // call entering method with class // name = GFG and method name = main logger.entering( GFG.class.getName(), "main", new String("Java is Platform Independent")); } } The output printed on log.txt is shown below. entering(String sourceClass, String sourceMethod, Object[] params): This method is used to Log a method entry, with an array of parameters. Actually many times in application development we need to log when we enter in a method of class so this is a convenience method that can be used to log entry to a method. This method logs with message "ENTRY" (followed by a format {N} indicator for each entry in the parameter array), log level FINER, and the given sourceMethod, sourceClass, and parameter are logged. Syntax: public void entering(String sourceClass, String sourceMethod, Object[] params) Parameters: This method accepts three parameters: sourceClass is the name of the class that issued the logging request and sourceMethod is the name of the method that is being entered. params: is an array of parameters to the method being entered. Return value: This method returns nothing. Below programs illustrate entering(String sourceClass, String sourceMethod, Object[] params) method: Program 1: Java // Java program to demonstrate // entering(String, String, Object[]) method import java.io.IOException; import java.util.logging.*; public class GFG { public static void main(String[] args) throws SecurityException, IOException { // Create a Logger Logger logger = Logger.getLogger( GFG.class.getName()); // Create a file handler object FileHandler handler = new FileHandler("logs.txt"); handler.setFormatter(new SimpleFormatter()); // Add file handler as // handler of logs logger.addHandler(handler); // set Logger level() logger.setLevel(Level.FINER); // create a array of String object String[] methods = { "main", "ADD", "get", "set" }; // call entering method with class // name = GFG and method name = main logger.entering(GFG.class.getName(), "main", methods); } } The output printed on log.txt is shown below. References: https://docs.oracle.com/javase/10/docs/api/java/util/logging/Logger.html#entering(java.lang.String, java.lang.String) https://docs.oracle.com/javase/10/docs/api/java/util/logging/Logger.html#entering(java.lang.String, java.lang.String, java.lang.Object) https://docs.oracle.com/javase/10/docs/api/java/util/logging/Logger.html#entering(java.lang.String, java.lang.String, java.lang.Object%5B%5D) Comment More infoAdvertise with us Next Article Logger entering() 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 log() Method in Java with Examples The log() method of Logger is used to Log a message. If the logger is currently enabled for the given message level which is passed as parameter then a corresponding LogRecord is created and forwarded to all the registered Output Handler objects. But in logger class, there are seven different log() 6 min read LogManager addLogger() method in Java with Examples The addLogger() method of java.util.logging.LogManager is used to insert the specified Logger in this LogManager instance. This Logger must be a named Logger. This method will add this Logger in this LogManager if it does not exist already. If it exists already, then this method returns false. Synta 2 min read Logger finest() method in Java with Examples The finest() method of a Logger class used to Log an FINEST message.This method is used to pass FINEST types logs to all the registered output Handler objects. FINEST message: FINEST provides highly detailed tracing message. There are two types of finest() method depending upon the number of the par 3 min read Logger throwing() method in Java with Examples throwing(String sourceClass, String sourceMethod, Throwable thrown) method is used to Log throwing an exception.In many scenario method is closed by throwing an exception then this is a very helpful method to log that a method is terminating by throwing an exception. The logging is done using the FI 2 min read Logger exiting() method in Java with Examples The exiting() method of a Logger class used to Log a method return. There are two types of exiting() method depending upon the parameters passed. exiting(String sourceClass, String sourceMethod): This method is used to Log a method return. we need to log what method returns and this is a convenience 3 min read Like