log4j

本文介绍了Log4j框架的优势及工作原理。通过合理的命名规则,开发者可以轻松地管理和配置不同层级的日志记录器。Log4j允许用户自定义输出目的地和格式,并能够根据预设的级别过滤日志消息。

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

The first and foremost advantage of any logging API over plain System.out.println resides in
For example, the logger named "com.foo" is a parent of the logger named "com.foo.Bar". Similarly, "java" is a parent of "java.util" and an ancestor of "java.util.Vector". This naming scheme should be familiar to most developers.
By definition, the printing method determines the level of a logging request.
This rule is at the heart of log4j
The developer is free to name the loggers as desired
seems to be the best strategy known so far.
If in addition a file appender is added to a logger, say C, then enabled logging requests forC and C's children will print on a file and on the console.
More often than not, users wish to customize not only the output destination but also the output format.
The layout is responsible for formatting the logging request according to the user's wishes,
whereas an appender takes care of sending the formatted output to its destination
Just as importantly, log4j will render the content of the log message according to user specified criteria.
Inserting log requests into the application code requires a fair amount of planning and effort.
Observation shows that approximately 4 percent of code is dedicated to logging. Consequently, even moderately sized applications will have thousands of logging statements embedded within their code.
Let us give a taste of how this is done with the help of an imaginary application MyApp that uses log4j.
The figure below depicts the object diagram of MyApp after just having called the BasicConfigurator.configure method.

As a side note, let me mention that
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值