浅谈log4j
不爱打字,贴代码。
- 导包
- 入门程序
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
//日志级别 all<debug<info<warn<error<fatal<off public static void main(String[] args) { Logger logger=Logger.getLogger(Test.class); //读取默认配置 BasicConfigurator.configure(); //配置日志级别,低于设置级别的 不会打印 logger.setLevel(Level.INFO); //打印语句 低于info级别的不会打印 logger.error("this is error"); logger.warn("this is warn"); logger.info("this is info"); logger.debug("this is debug"); }
- 结果打印
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
0 [main] ERROR log4j.Test - this is error 1 [main] WARN log4j.Test - this is warn 1 [main] INFO log4j.Test - this is info
posted on 2018-06-03 20:02 Danial7777777 阅读(111) 评论(0) 编辑 收藏 举报