log4j - Log4j API 有什么用?

标签 log4j

我将在我的 Web 应用程序中使用 Log4j,我是新手。 Log4j 的用途是什么以及我如何在我的应用程序中使用它。提前致谢。

最佳答案

我认为Log4J home page提供了其使用背后的最佳概述和基本原理。

With log4j it is possible to enable logging at runtime without modifying the application binary. The log4j package is designed so that these statements can remain in shipped code without incurring a heavy performance cost. Logging behavior can be controlled by editing a configuration file, without touching the application binary.

Logging equips the developer with detailed context for application failures. On the other hand, testing provides quality assurance and confidence in the application. Logging and testing should not be confused. They are complementary. When logging is wisely used, it can prove to be an essential tool.



除此之外,使用 Log4J,您可以动态地打开/关闭日志记录。您可以动态更改格式(您想要时间戳吗?日期戳?)并且您可以更改日志记录的位置(到控制台?到文件?到数据库?),所有这些都不需要更改您的代码。

关于log4j - Log4j API 有什么用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1492309/

相关文章:

java - 将 java 代码转换为 jar 文件后在何处包含日志属性文件

java - Slf4j 库排除 log4j 的 Sonatype 安全漏洞

java - log4j.xml 将滚动文件移动到另一个目录/位置?

java - log4j:防止重复日志消息的标准方法?

java - Gradle 依赖项 (org.apache.commons ) 是否也受到当前 log4j 漏洞的影响?

java - Log4J 仅将一个类附加到附加程序

java - 使用 log4j2 实现记录器

java - 多个功能是 logback 标记的良好用例吗?

java - 从日志文件解析 Log4j 布局

java - ClassCastException : org. slf4j.impl.Log4jLoggerAdapter 无法转换为 ch.qos.logback.classic.Logger