當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Java Logger getUseParentHandlers()用法及代碼示例


Logger類的getUseParentHandlers()方法用於獲取作為布爾值的值,該值回答此logger是否將其輸出發送到其父logger。

用法:

public boolean getUseParentHandlers()

參數:此方法不接受任何內容。


返回值:如果要將輸出發送到記錄器的父級,則此方法返回true。

以下示例程序旨在說明getUseParentHandlers()方法:

示例1:

// 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上打印的輸出如下所示-

示例2:

// 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://docs.oracle.com/javase/10/docs/api/java/util/logging/Logger.html#getUseParentHandlers()



相關用法


注:本文由純淨天空篩選整理自AmanSingh2210大神的英文原創作品 Logger getUseParentHandlers() Method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。