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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。