📜  Java中的 Logger getUseParentHandlers() 方法及示例

📅  最后修改于: 2022-05-13 01:55:31.691000             🧑  作者: Mango

Java中的 Logger getUseParentHandlers() 方法及示例

Logger类的getUseParentHandlers()方法用于获取布尔值的值,它回答此记录器是否将其输出发送到其父记录器。

句法:

public boolean getUseParentHandlers()

参数:此方法不接受任何内容。

返回值:如果要将输出发送到记录器的父级,则此方法返回 true。

下面的程序说明了 getUseParentHandlers() 方法:

方案一:

// Java program to demonstrate
// Logger.getUseParentHandlers() method
  
import java.util.logging.Logger;
  
public class GFG {
  
    private static Logger logger
        = Logger.getLogger(
            GFG.class
                .getPackage()
                .getName());
  
    public static void main(String args[])
    {
  
        // Check output is to be
        // sent to the logger's parent
        boolean flag
            = logger.getUseParentHandlers();
  
        // Log the flag value
        logger.info("output sent to the"
                    + " logger's parent - "
                    + flag);
    }
}

eclipse IDE上打印的输出如下所示 -

方案二:

// Java program to demonstrate
// Logger.getUseParentHandlers() method
  
import java.util.logging.Logger;
  
public class GFG {
  
    private static Logger logger
        = Logger.getLogger(
            GFG.class
                .getPackage()
                .getName());
  
    public static void main(String args[])
    {
  
        // Set setUseParentHandlers
        logger.setUseParentHandlers(false);
  
        // Check output is to be
        // sent to the logger's parent
        boolean flag = logger.getUseParentHandlers();
  
        // Print value
        System.out.println("output sent to the"
                           + " logger's parent - "
                           + flag);
    }
}

eclipse IDE上打印的输出如下所示 -

参考: https: Java/util/logging/Logger.html#getUseParentHandlers()