JAVA中使用commons-logging和log4j打印日志
来源:互联网 发布:微信支付 域名备案 编辑:程序博客网 时间:2024/06/06 03:52
<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">一、下载好commons-logging-1.1.3.jar和log4j-1.2.16.jar两个JAVA包,放到lib目录下,并添加到.classpath文件中</span>
二、在src目录下新建一个log4j.properties文件,文件内容如下:
# definition of root
log4j.rootLogger=DEBUG,console
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=[%d{yyyy-MM-dd HH:mm:ss.SSS}][%5p] [%F %L] || %m %n
log4j.appender.console.Threshold=DEBUG
根据实际的使用得知,log4j.rootLogger和log4j.appender.console.Threshold中的日志级别配置,可以控制打印的最高日志级别,比如log4j.rootLogger配置的是DEBUG,而log4j.appender.console.Threshold中配置的是INFO,那么日志最高只会打印INFO级别,而不会打印DEBUG级别。
三、测试代码
package scripts.testscript;<span style="color:#ff0000;">import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;</span>import org.testng.annotations.Test;public class LogPrintTestScript {<span style="color:#ff0000;">private final static Log logger = LogFactory.getLog(LogPrintTestScript.class);</span>@Testpublic void run() {logger.debug("debug log test");logger.info("info log test");logger.warn("warn log test");logger.error("error log test");}}
0 0
- JAVA中使用commons-logging和log4j打印日志
- java 使用commons-logging和log4j记录日志
- 使用commons-logging和log4j记录日志
- 使用commons-logging和log4j记录日志
- 使用commons-logging和log4j记录日志
- spring 中使用 logback打印日志,替换其他日志如log4j,commons-logging
- apache commons Logging与Log4j关系和只导入apache commons Logging为何能打印日志
- Apache通用日志工具commons-logging和Log4j使用总结
- Apache通用日志工具commons-logging和Log4j使用
- Apache通用日志工具commons-logging和Log4j使用总结
- 使用commons-logging和Log4j记录日志学习总结
- Apache通用日志工具commons-logging和Log4j使用总结
- 使用commons.logging结合log4j显示调试和日志信息
- 使用commons-logging和log4j记录日志[转载]
- Apache通用日志工具commons-logging和Log4j使用总结
- Apache通用日志工具commons-logging和Log4j使用总结
- Apache通用日志工具commons-logging和Log4j使用总结
- Apache通用日志工具commons-logging和Log4j使用总结
- 简单服务器生猛上手
- Android基础——自定义EditTExt实现去掉输入框添加下划线
- 从Samples中入门IOS开发(四)------ 基于socket的网络编程
- c++作业2——模拟ATM机
- leetcode——231—— Power of Two
- JAVA中使用commons-logging和log4j打印日志
- leetcode刷题,总结,记录,备忘78
- EasyDarwin流媒体云平台架构
- https通信加密过程
- leetcode 322. Coin Change-硬币交换|动态规划
- POJ 1470 Closest Common Ancestors【LCA Tarjan】
- 删除已经配置的类库和移除CocoaPods
- jinja2
- 从Samples中入门IOS开发(五)------ 基于HTTP的网络编程