Logger類的isLoggable()方法用於返回布爾值形式的響應,該響應為查詢提供答案,即如果給定級別的消息實際上是否由該記錄器記錄,則為該記錄。此檢查基於Loggers有效級別,該級別可以從其父級繼承。
用法:
public boolean isLoggable(Level level)
參數:此方法接受一個表示消息日誌記錄級別的參數級別。
返回值:如果當前正在記錄給定的消息級別,則此方法返回true。
以下示例程序旨在說明isLoggable()方法:
示例1:
// Java program to demonstrate
// Logger.isLoggable() method
import java.util.logging.*;
public class GFG {
private static Logger logger
= Logger.getLogger(
GFG.class.getName());
public static void main(String args[])
{
// Check if the Level.INFO
// is currently being logged.
boolean flag
= logger.isLoggable(
Level.INFO);
// Print value
System.out.println("The Level.INFO"
+ " is currently being logged - "
+ flag);
}
}
輸出:
The Level.INFO is currently being logged - true
示例2:
// Java program to demonstrate
// Logger.isLoggable() method
import java.util.logging.*;
public class GFG {
private static Logger logger
= Logger.getLogger(
GFG.class.getName());
public static void main(String args[])
{
// Check if the Level.OFF
// is currently being logged.
boolean flag
= logger.isLoggable(Level.OFF);
// Print value
System.out.println("The Level.OFF"
+ " is currently being logged - "
+ flag);
}
}
輸出:
The Level.OFF is currently being logged - true
相關用法
- Java Logger log()用法及代碼示例
- Java Logger getGlobal()用法及代碼示例
- Java Logger getResourceBundle()用法及代碼示例
- Java Logger getName()用法及代碼示例
- Java Logger getParent()用法及代碼示例
- Java Logger getUseParentHandlers()用法及代碼示例
- Java Logger getResourceBundleName()用法及代碼示例
- Java Logger setFilter()用法及代碼示例
- Java Logger exiting()用法及代碼示例
- Java Logger getLevel()用法及代碼示例
- Java Logger throwing()用法及代碼示例
- Java Logger getHandler()用法及代碼示例
- Java Logger getFilter()用法及代碼示例
- Java Logger entering()用法及代碼示例
注:本文由純淨天空篩選整理自AmanSingh2210大神的英文原創作品 Logger isLoggable() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。