Log4j简单应用 博客分类: J2SE log4jJavathreadApacheJ#
Log4j主页:http://logging.apache.org/
Log4j是一款强大的日志记录工具,允许用户对日志记录作出灵活的定义。
测试程序:
package org.eleaf.log4j; import java.io.IOException; import org.apache.log4j.Logger; public class Log4jTest { } |
log4jtest.properties属性文件:(应与Log4jTest.class在同一目录中)
##info指明日志级别,stdout,file是两个不同的输出目的地。 log4j.rootLogger=info, stdout, file ##输出目的地stdout,即标准输出。 log4j.appender.stdout=org.apache.log4j.ConsoleAppender ##定义输出格式:
##输出目的地file,输出到文件log4jtest.log。 log4j.appender.file=org.apache.log4j.FileAppender
|
控制台标准输出结果:
[run:0][date:2005-10-18 17:16:58][catalog:java.lang.Class][priority:INFO][message:Begin Log4jTest][location:org.eleaf.log4j.Log4jTest.main(Log4jTest.java:22)][thread:main] [run:31][date:2005-10-18 17:16:58][catalog:java.lang.Class][priority:WARN][message:0/8=0][location:org.eleaf.log4j.Log4jTest.main(Log4jTest.java:28)][thread:main] [run:31][date:2005-10-18 17:16:58][catalog:java.lang.Class][priority:WARN][message:1/1=1][location:org.eleaf.log4j.Log4jTest.main(Log4jTest.java:28)][thread:main] [run:47][date:2005-10-18 17:16:58][catalog:java.lang.Class][priority:WARN][message:2/8=0][location:org.eleaf.log4j.Log4jTest.main(Log4jTest.java:28)][thread:main] [run:47][date:2005-10-18 17:16:58][catalog:java.lang.Class][priority:ERROR][message:error:/ by zero][location:org.eleaf.log4j.Log4jTest.main(Log4jTest.java:30)][thread:main] [run:47][date:2005-10-18 17:16:58][catalog:java.lang.Class][priority:WARN][message:4/4=1][location:org.eleaf.log4j.Log4jTest.main(Log4jTest.java:28)][thread:main] [run:47][date:2005-10-18 17:16:58][catalog:java.lang.Class][priority:ERROR][message:error:/ by zero][location:org.eleaf.log4j.Log4jTest.main(Log4jTest.java:30)][thread:main] [run:47][date:2005-10-18 17:16:58][catalog:java.lang.Class][priority:WARN][message:6/9=0][location:org.eleaf.log4j.Log4jTest.main(Log4jTest.java:28)][thread:main] [run:47][date:2005-10-18 17:16:58][catalog:java.lang.Class][priority:WARN][message:7/4=1][location:org.eleaf.log4j.Log4jTest.main(Log4jTest.java:28)][thread:main] [run:47][date:2005-10-18 17:16:58][catalog:java.lang.Class][priority:WARN][message:8/1=8][location:org.eleaf.log4j.Log4jTest.main(Log4jTest.java:28)][thread:main] [run:47][date:2005-10-18 17:16:58][catalog:java.lang.Class][priority:WARN][message:9/9=1][location:org.eleaf.log4j.Log4jTest.main(Log4jTest.java:28)][thread:main] [run:47][date:2005-10-18 17:16:58][catalog:java.lang.Class][priority:INFO][message:End Log4jTest][location:org.eleaf.log4j.Log4jTest.main(Log4jTest.java:33)][thread:main] |
日志文件输出结果:
[run:0][date:2005-10-18 17:16:58][catalog:java.lang.Class][priority:INFO
][message:Begin Log4jTest][location:org.eleaf.log4j.Log4jTest.main(Log4jTest.java:22)][thread:main] [run:31][date:2005-10-18 17:16:58][catalog:java.lang.Class][priority:WARN][message:0/8=0][location:org.eleaf.log4j.Log4jTest.main(Log4jTest.java:28)][thread:main] [run:31][date:2005-10-18 17:16:58][catalog:java.lang.Class][priority:WARN][message:1/1=1][location:org.eleaf.log4j.Log4jTest.main(Log4jTest.java:28)][thread:main] [run:47][date:2005-10-18 17:16:58][catalog:java.lang.Class][priority:WARN][message:2/8=0][location:org.eleaf.log4j.Log4jTest.main(Log4jTest.java:28)][thread:main] [run:47][date:2005-10-18 17:16:58 ][catalog:java.lang.Class ][priority:ERROR ][message:error:/ by zero ][location:org.eleaf.log4j.Log4jTest.main(Log4jTest.java:30 )][thread:main ] [run:47][date:2005-10-18 17:16:58][catalog:java.lang.Class][priority:WARN][message:4/4=1][location:org.eleaf.log4j.Log4jTest.main(Log4jTest.java:28)][thread:main ] [run:47][date:2005-10-18 17:16:58][catalog:java.lang.Class][priority:ERROR][message:error:/ by zero][location:org.eleaf.log4j.Log4jTest.main(Log4jTest.java:30)][thread:main ] [run:47][date:2005-10-18 17:16:58][catalog:java.lang.Class][priority:WARN][message:6/9=0][location:org.eleaf.log4j.Log4jTest.main(Log4jTest.java:28)][thread:main] [run:47][date:2005-10-18 17:16:58][catalog:java.lang.Class][priority:WARN][message:7/4=1][location:org.eleaf.log4j.Log4jTest.main(Log4jTest.java:28)][thread:main] [run:47][date:2005-10-18 17:16:58][catalog:java.lang.Class][priority:WARN][message:8/1=8][location:org.eleaf.log4j.Log4jTest.main(Log4jTest.java:28)][thread:main] [run:47][date:2005-10-18 17:16:58][catalog:java.lang.Class][priority:WARN][message:9/9=1][location:org.eleaf.log4j.Log4jTest.main(Log4jTest.java:28)][thread:main] [run:47][date:2005-10-18 17:16:58][catalog:java.lang.Class][priority:INFO ][message:End Log4jTest][location:org.eleaf.log4j.Log4jTest.main(Log4jTest.java:33)][thread:main] |
下一篇: 数据类型的转换
推荐阅读
-
Log4j简单应用 博客分类: J2SE log4jJavathreadApacheJ#
-
最简单的平衡树(红-黑树)的实现 博客分类: 算法J2SE 算法二叉平衡树2-3树红黑树
-
Spring Bean简单应用实例 博客分类: Spring Spring Bean简单应用实例装配beanbean注入
-
Spring Bean简单应用实例 博客分类: Spring Spring Bean简单应用实例装配beanbean注入
-
zookeeper注册服务与netty的简单结合应用 博客分类: zookeeper zookeepernettyha
-
Consul-template的简单应用:配置中心,服务发现与健康监测 博客分类: Consul-templateConsul consulconsul template架构集群
-
Consul-template的简单应用:配置中心,服务发现与健康监测 博客分类: Consul-templateConsul consulconsul template架构集群
-
耶鲁CAS代理认证的代码及简单ppt 博客分类: 默认类别 JSP应用服务器Google浏览器
-
耶鲁CAS代理认证的代码及简单ppt 博客分类: 默认类别 JSP应用服务器Google浏览器
-
ORM其实是在映射网络模型和关系模型,OO的关系模型无需映射,且更简单高效 博客分类: 思想 OO网络应用领域模型ORM数据结构