Logger config() method in Java with Examples
The config() method of a Logger class used to Log an config message. This method is used to pass config types logs to all the registered output Handler objects.
Config Level: Configuration Information may be like what CPU the application is running on, how much is the disk and memory space.
There are two types of config() method depending upon the number of parameters passed.
-
config(String msg): This method is used to log a CONFIG message. If the logger is enabled for logging CONFIG level message then the given message is forwarded to all the registered output Handler objects.
Syntax:
public void config(String msg)
Parameters: This method accepts a single parameter String which is the string message.
Return value: This method returns nothing.
Below programs illustrate config(String msg) method:
Program 1:
// Java program to demonstrate// Logger.config(String msg) methodimportjava.io.IOException;importjava.util.logging.*;publicclassGFG {publicstaticvoidmain(String[] args)throwsSecurityException, IOException{// Create a LoggerLogger logger= Logger.getLogger(GFG.class.getName());// Create a file handler objectFileHandler handler=newFileHandler("logs.txt");// Add file handler as// handler of logslogger.addHandler(handler);// Set Logger level()logger.setLevel(Level.CONFIG);// Call config methodlogger.config("Set Geeks=CODING");}}chevron_rightfilter_noneThe output printed on logs.txt file is shown below.
Output:

Program 2:
// Java program to demonstrate// Logger.config(String msg) methodimportjava.io.IOException;importjava.util.logging.*;publicclassGFG {publicstaticvoidmain(String[] args)throwsSecurityException, IOException{// Create a LoggerLogger logger= Logger.getLogger(GFG.class.getName());// Create a file handler objectFileHandler handler=newFileHandler("logs.txt");// Add file handler as// handler of logslogger.addHandler(handler);// Set Logger level()logger.setLevel(Level.CONFIG);// Call config methodlogger.config("This is config message 1");logger.config("This is config message 2");}}chevron_rightfilter_noneThe output printed on logs.txt file is shown below.
Output:
-
config(Supplier msgSupplier): This method is used Log a CONFIG 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 CONFIG 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 config(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 config(Supplier msgSupplier) method:
Program 1:
// Java program to demonstrate// Logger.config(Supplier<String>) methodimportjava.io.IOException;importjava.util.function.Supplier;importjava.util.logging.*;publicclassGFG {publicstaticvoidmain(String[] args)throwsSecurityException, IOException{// Create a LoggerLogger logger= Logger.getLogger(GFG.class.getName());// Create a file handler objectFileHandler handler=newFileHandler("logs.txt");// Add file handler as// handler of logslogger.addHandler(handler);// Set Logger level()logger.setLevel(Level.CONFIG);// Create a supplier<String> methodSupplier<String> StrSupplier= () ->newString("Welcome to GFG");// Call config(Supplier<String>)logger.config(StrSupplier);}}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#config(java.lang.String)
- https://docs.oracle.com/javase/10/docs/api/java/util/logging/Logger.html#config(java.util.function.Supplier)
Recommended Posts:
- Logger log() Method in Java with Examples
- Logger getResourceBundleName() method in Java with Examples
- Logger warning() method in Java with Examples
- Logger setLevel() method in Java with Examples
- Logger fine() method in Java with Examples
- Logger throwing() method in Java with Examples
- Logger setFilter() method in Java with Examples
- Logger addHandler() method in Java with Examples
- Logger getName() Method in Java with Examples
- Logger severe() method in Java with Examples
- Logger finest() method in Java with Examples
- Logger isLoggable() method in Java with Examples
- Logger finer() method in Java with Examples
- Logger getParent() Method in Java with Examples
- Logger getGlobal() 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.



