LogRecord setResourceBundle() method in Java with Examples

The setResourceBundle() method of java.util.logging.LogRecord is used to set the localization resource bundle.Resource bundle used to localize the message of this LogRecord.

Syntax:

public void setResourceBundle(ResourceBundle bundle)

Parameters: This method accepts bundle which is the localization bundle and it may be null.

Return: This method returns nothing.

Below programs illustrate setResourceBundle() method:
Program 1:



filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to illustrate setResourceBundle() method
  
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.ResourceBundle;
  
public class GFG {
  
    public static void main(String[] args)
    {
  
        // Create LogRecord object
        LogRecord logRecord = new LogRecord(
            Level.parse("800"),
            "Hi Logger");
  
        // Create ResourceBundle using getBundle
        // myResource is a properties file
        ResourceBundle bundle
            = ResourceBundle
                  .getBundle("myResource");
  
        // set ResourceBundle
        logRecord.setResourceBundle(bundle);
  
        // print the ResourceBundle details
        System.out.println(
            "Resource Bundle = "
            + logRecord
                  .getResourceBundle()
                  .getBaseBundleName());
    }
}

chevron_right


Output:

Resource Bundle = myResource

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to illustrate setResourceBundle() method
  
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.ResourceBundle;
public class GFG {
  
    public static void main(String[] args)
    {
  
        // Create LogRecord object
        LogRecord logRecord = new LogRecord(
            Level.parse("800"),
            "Hi Logger");
  
        // Create ResourceBundle having null value
        ResourceBundle bundle
            = null;
  
        // set ResourceBundle
        logRecord.setResourceBundle(bundle);
  
        // print the ResourceBundle details
        System.out.println(
            "Resource Bundle = "
            + logRecord.getResourceBundle());
    }
}

chevron_right


Output:

Resource Bundle = null

References: https://docs.oracle.com/javase/8/docs/api/java/util/logging/LogRecord.html#setResourceBundle(java.util.ResourceBundle)

Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.