Friday, September 5, 2025
HomeLanguagesJavaLogger getResourceBundle() Method in Java with Examples

Logger getResourceBundle() Method in Java with Examples

getResourceBundle() method of a Logger class is used to localise resource bundle for this logger. We can set ResourceBundle either by the setResourceBundle method or mapped from the resource bundle name set via the getLogger factory method for the current default locale and this method will return a ResourceBundle set by above-mentioned ways. If the result is null, then the Logger will use a resource bundle or resource bundle name inherited from its parent.
Syntax: 
 

public ResourceBundle getResourceBundle()

Parameters: This method accepts nothing.
Return value: This method return localization bundle.
Below programs illustrate the getResourceBundle() method: 
Program 1: 
 

Java




// Java program to demonstrate
// Logger.getParent() method
 
import java.util.logging.*;
import java.util.ResourceBundle;
 
public class GFG {
 
    private static Logger logger
        = Logger.getLogger(
            String
                .class
                .getPackage()
                .getName());
 
    public static void main(String args[])
    {
 
        logger.info("printing the message...");
 
        ResourceBundle rs
            = logger.getResourceBundle();
 
        logger.info("Resource Bundle " + rs);
    }
}


Output: 
The output printed on eclipse IDE shown below- 
 

Program 2: 
 

Java




// Java program to demonstrate
// Logger.getParent() method
 
import java.util.logging.*;
import java.util.ResourceBundle;
 
public class GFG {
 
    private static Logger logger
        = Logger.getLogger(
            GFG
                .class
                .getPackage()
                .getName());
 
    public static void main(String args[])
    {
 
        // Create ResourceBundle using getBundle
        // myResource is a properties file
        ResourceBundle bundle
            = ResourceBundle
                  .getBundle("myResource");
 
        // Set ResourceBundle to logger
        logger.setResourceBundle(bundle);
 
        // Get ResourceBundle from logger
        ResourceBundle rs
            = logger.getResourceBundle();
 
        // Log the ResourceBundle details
        logger.info("Resource Bundle "
                    + rs.getBaseBundleName());
    }
}


For above program there is a properties file name myResource. we have to add this file along side the class to execute the program. 
Output: 
The output printed on eclipse IDE shown below- 
 

Reference: https://docs.oracle.com/javase/10/docs/api/java/util/logging/Logger.html#getResourceBundle()
 

RELATED ARTICLES

Most Popular

Dominic
32269 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6637 POSTS0 COMMENTS
Nicole Veronica
11802 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11865 POSTS0 COMMENTS
Shaida Kate Naidoo
6752 POSTS0 COMMENTS
Ted Musemwa
7027 POSTS0 COMMENTS
Thapelo Manthata
6704 POSTS0 COMMENTS
Umr Jansen
6721 POSTS0 COMMENTS