Java Logging: Log Levels

本文深入探讨了Java中日志系统的工作原理,包括内置的日志级别及其使用方式,以及如何通过设置日志级别来过滤消息。通过示例代码,详细解释了如何配置日志级别以忽略特定级别的日志消息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Table of Contents

When a message is logged via a Logger it is logged with a certain log level. The built-in log levels are:

  • SEVERE
  • WARNING
  • INFO
  • CONFIG
  • FINE
  • FINER
  • FINEST

The log level is represented by the class java.util.logging.Level. This class contains a constant for each of the above log levels. It is one of these constants you use when you log a message to a Logger. Here is an example:

logger.log(Level.SEVERE, "A severe message!");

Filtering Messages

You can filter the messages by their log level, meaning you can configure a Logger to not log, and not propagate messages below a certain level. Here is an example of that:

logger.setLevel(Level.WARNING);

The Logger now ignores all messages below the log level WARNING.

To understand how log levels behave in the Logger hierarchy, check out the text on the Logger hierarchy.

转载于:https://www.cnblogs.com/hephec/p/4579624.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值