Logger warning() method in Java with Examples Last Updated : 27 Mar, 2019 Comments Improve Suggest changes Like Article Like Report The warning() method of a Logger class used to Log a WARNING message.This method is used to pass WARNING types logs to all the registered output Handler objects. WARNING Message: Warning may occur whenever the user has given wrong input or credentials. There are two types of warning() method depending upon no of the parameter passed. warning(String msg): This method is used to log a WARNING message. If the logger is enabled for logging WARNING level message then the given message is forwarded to all the registered output Handler objects. Syntax: public void warning(String msg) Parameters: This method accepts a single parameter String which is the string message. Return value: This method returns nothing. Below programs illustrate warning(String msg) method: Program 1: Java // Java program to demonstrate // Logger.warning(String msg) 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()); // Set Logger level() logger.setLevel(Level.WARNING); // Call warning method logger.warning("Set WARNING = ERRORS"); } } The output printed on console is shown below. Output: warning(Supplier msgSupplier): This method is used Log a WARNING message, constructed only if the logging level is such that the message will actually be logged. It means If the logger is enabled for the WARNING message level then the message is constructed by invoking the provided supplier function and forwarded to all the registered output Handler objects. Syntax: public void warning(Supplier msgSupplier) Parameters: This method accepts a single parameter msgSupplier which is a function, which when called, produces the desired log message. Return value: This method returns nothing. Below programs illustrate warning(Supplier msgSupplier) method: Program 1: Java // Java program to demonstrate // Logger.warning(Supplier<String>) method import java.io.IOException; import java.util.function.Supplier; 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()); // Set Logger level() logger.setLevel(Level.WARNING); // Create a supplier<String> method Supplier<String> StrSupplier = () -> new String("WARNING WARNING WARNING"); // Call warning(Supplier<String>) logger.warning(StrSupplier); } } The output printed on console is shown below. Output: References: https://docs.oracle.com/javase/10/docs/api/java/util/logging/Logger.html#warning(java.lang.String) https://docs.oracle.com/javase/10/docs/api/java/util/logging/Logger.html#warning(java.util.function.Supplier) Comment More infoAdvertise with us Next Article Logger warning() 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 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 info(String) method in Java with Examples The info() method of a Logger class is used to Log an INFO message. This method is used to forward logs to all the registered output Handler objects. INFO message: Info is for the use of administrators or advanced users. It denotes mostly the actions that have led to a change in state for the applic 3 min read Logger severe() method in Java with Examples The severe() method of a Logger class used to Log a SEVERE message.This method is used to pass SEVERE types logs to all the registered output Handler objects. SEVERE Message: Severe occurs when something terrible has occurred and the application cannot continue further. Ex like database unavailable, 2 min read 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 Logger fine() method in Java with Examples The fine() method of a Logger class used to Log a FINE message. This method is used to pass FINE types logs to all the registered output Handler objects. FINE, FINER and FINEST provide tracking information as when what is happening/ has happened in our application. FINE displays the most important m 3 min read Like