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 method that can be used to log returning from a method. This method logs with the message “RETURN”, log level FINER, and the given sourceMethod and sourceClass are also logged.
Syntax:
public void exiting(String sourceClass, String sourceMethod)Parameters: This method accepts two parameters:
- sourceClass is the name of the class that issued the logging request,
- sourceMethod is the name of the method
Return value: This method returns nothing.
Below program illustrate exiting(String sourceClass, String sourceMethod) method:
Program 1:// Java program to demonstrate// exiting(String, String) methodimportjava.io.IOException;importjava.util.logging.FileHandler;importjava.util.logging.Level;importjava.util.logging.Logger;importjava.util.logging.SimpleFormatter;publicclassGFG {publicstaticvoidmain(String[] args)throwsSecurityException, IOException{// Create a LoggerLogger logger= Logger.getLogger(GFG.class.getName());// Create a file handler objectFileHandler handler=newFileHandler("logs.txt");handler.setFormatter(newSimpleFormatter());// Add file handler as// handler of logslogger.addHandler(handler);// set Logger level()logger.setLevel(Level.FINER);// call exiting methods with class// name = GFG and method name = mainlogger.exiting(GFG.class.getName(),GFG.class.getMethods()[0].getName());}}chevron_rightfilter_noneThe output printed on log.txg file is shown below.
Output:

-
exiting(String sourceClass, String sourceMethod, Object result): This method is used to Log a method entry, with result object. This is a very helpful method to log entry related to a method of a class with its return value. This method logs with the message “RETURN {0}”, log level FINER, and the gives sourceMethod, sourceClass, and result object is logged.
Syntax:
public void exiting(String sourceClass, String sourceMethod, Object result)Parameters: This method accepts three parameters:
- sourceClass is the name of the class that issued the logging request,
- sourceMethod is the name of the method and
- Object that is being returned.
Return value: This method returns nothing.
Below programs illustrate exiting(String sourceClass, String sourceMethod, Object result) method:
Program 1:// Java program to demonstrate// exiting(String, String, Object) methodimportjava.io.IOException;importjava.util.logging.FileHandler;importjava.util.logging.Level;importjava.util.logging.Logger;importjava.util.logging.SimpleFormatter;publicclassGFG {publicstaticvoidmain(String[] args)throwsSecurityException, IOException{// Create a LoggerLogger logger= Logger.getLogger(GFG.class.getName());// Create a file handler objectFileHandler handler=newFileHandler("logs.txt");handler.setFormatter(newSimpleFormatter());// Add file handler as// handler of logslogger.addHandler(handler);// set Logger level()logger.setLevel(Level.FINER);// set Logger level()logger.setLevel(Level.FINER);// call exiting method with class// name = GFG and method name = mainlogger.exiting(GFG.class.getName(),GFG.class.getMethods()[0].getName(),newString("Java is Platform Independent"));}}chevron_rightfilter_noneThe output printed on log.txt is shown below.
Output:
References:
- https://docs.oracle.com/javase/10/docs/api/java/util/logging/Logger.html#exiting(java.lang.String, java.lang.String, java.lang.Object)
- https://docs.oracle.com/javase/10/docs/api/java/util/logging/Logger.html#exiting(java.lang.String, java.lang.String)
Recommended Posts:
- Logger log() Method in Java with Examples
- Logger config() method in Java with Examples
- Logger getParent() Method in Java with Examples
- Logger removeHandler() method in Java with Examples
- Logger setLevel() method in Java with Examples
- Logger getResourceBundle() Method in Java with Examples
- Logger throwing() method in Java with Examples
- Logger fine() method in Java with Examples
- Logger getGlobal() Method in Java with Examples
- Logger getUseParentHandlers() Method in Java with Examples
- Logger setFilter() method in Java with Examples
- Logger addHandler() method in Java with Examples
- Logger isLoggable() method in Java with Examples
- Logger getLogger() Method in Java with Examples
- Logger setResourceBundle() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



