`
Poechant
  • 浏览: 212442 次
博客专栏
Bebe66e7-3a30-3fc9-aeea-cfa3b474b591
Nginx高性能Web服务...
浏览量:23509
5738817b-23a1-3a32-86de-632d7da73b1e
Cumulus实时媒体服务...
浏览量:21414
社区版块
存档分类
最新评论

Java日志服务入门系列教程——(2)Apache log4j入门

 
阅读更多

1. 概述

目前log4j有三个发展分支,一个是1.2的稳定版,一个是已经停止继续发展的1.3版本,另一个就是实验阶段的2.0版本。Apache log4j官网上称,在一台载有运行在800MHz的AMD Duron CPU并使用JDK 1.3.1 上的计算机中,log4j 1.2 只需要5纳秒就可以完成一个日志语句是应该作为日志输出还是不输出的决定。


2. 下载log4j 1.2 API library

从人人网的实验室下载:

http://labs.renren.com/apache-mirror//logging/log4j/1.2.16/apache-log4j-1.2.16.zip

从BJTU下载:

http://mirror.bjtu.edu.cn/apache//logging/log4j/1.2.16/apache-log4j-1.2.16.zip


3. log4j的Hello World 程序源代码

package com.sinosuperman.log4j;

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;

public class Test {
	private static final Logger logger = Logger.getLogger(Test.class);
	public static void main(String[] args) {
		BasicConfigurator.configure();
		logger.info("Hello World, This is an information message.");
		logger.error("Hello World, This is a error message.");
		logger.warn("Hello World, This is a warning message.");
		logger.debug("Hello World, This is a debugging message.");
		logger.fatal("Hello World, This is a fatal message.");
		System.exit(0);
	}
}

4. log4j的Hello World 程序运行结果

1 [main] INFO com.sinosuperman.log4j.Test  - Hello World, This is an information message.
3 [main] ERROR com.sinosuperman.log4j.Test  - Hello World, This is a error message.
3 [main] WARN com.sinosuperman.log4j.Test  - Hello World, This is a warning message.
3 [main] DEBUG com.sinosuperman.log4j.Test  - Hello World, This is a debugging message.
3 [main] FATAL com.sinosuperman.log4j.Test  - Hello World, This is a fatal message.


分享到:
评论

相关推荐

    Apache Log4j2 远程代码执行漏洞检测工具

    Apache Log4j2 远程代码执行漏洞检测工具,包含windows版和linux版。图形化 Apache Log4j2检测工具

    Apache Log4j2紧急缓解措施.docx

    Apache Log4j2紧急缓解措施

    Apache Log4j 2 (apache-log4j-2.17.1-bin.zip)

    Apache Log4j 2 (apache-log4j-2.17.1-bin.zip)是对 Log4j 的升级,它比其前身 Log4j 1.x 提供了重大改进,并提供了 Logback 中可用的许多改进,同时修复了 Logback 架构中的一些固有问题。修复了安全漏洞 CVE-...

    apache-log4j-2.0

    Apache Log4j 2.0 发布第 4 个 Beta 版本,包括的新特性有: o Added Log4j 2 to SLF4J adapter. o LOG4J2-131: Add SMTPAppender. Thanks to Scott Severtson. o Added hostName and contextName to property ...

    apache-log4j-2.17.0 核心jar包

    Log4j 是一个日志记录框架,Log4j 2 是对 Log4j 的升级,提供了重大改进,超越其前身 Log4j 1.x,并提供许多其它现代功能 ,例如对标记的支持、使用查找的属性替换、lambda 表达式与日志记录时无垃圾等。 Apache ...

    Apache Log4j 2 源代码( apache-log4j-2.17.1-src.tar.gz)

    Apache Log4j 2 源代码( apache-log4j-2.17.1-src.tar.gz) 是对 Log4j 的升级,它比其前身 Log4j 1.x 提供了重大改进,并提供了 Logback 中可用的许多改进,同时修复了 Logback 架构中的一些固有问题。修复了安全...

    apache log4j 日志系统实现原理.doc

    apache log4j 日志系统实现原理.doc,Apache Log4j 学习笔记 Apache Logging Project Homepage: http://logging.apache.org

    Apache Log4j 2 (apache-log4j-2.17.1-bin.tar.gz)

    Apache Log4j 2 (apache-log4j-2.17.1-bin.tar.gz)是对 Log4j 的升级,它比其前身 Log4j 1.x 提供了重大改进,并提供了 Logback 中可用的许多改进,同时修复了 Logback 架构中的一些固有问题。修复了安全漏洞 CVE-...

    Apache Log4j_1.2.17 完整依赖包

    Apache Log4j_1.2.17 完整依赖包,在jdk1.8.201中测试通过。使用教程https://www.tutorialspoint.com/springmvc/springmvc_log4j.htm

    logging-log4j2, Apache日志记录Log4J2镜像.zip

    logging-log4j2, Apache日志记录Log4J2镜像 Apache Log4J 2Apache是对 Log4J的升级,它提供了比它的前辈 Log4J 1. x,的显著改进,并提供了许多改进,同时解决了soa架构中一些固有问题。 在Github上请求请求通过发送...

    apache-log4j-extras-1.2.17-API文档-中文版.zip

    标签:apache、extras、log4j、jar包、java、API文档、中文版; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档内容。 人性化翻译,文档中的代码和结构保持不变,注释和说明精准翻译...

    解决Apache Log4j 远程代码执行漏洞log4j2部分jar

    解决Apache Log4j 远程代码执行漏洞log4j2部分jar,包含log4j-1.2-api-2.15.0.jar,log4j-api-2.15.0.jar,log4j-core-2.15.0.jar,log4j-to-slf4j-2.15.0.jar

    Apache Log4j 2代码漏洞处置指南及检测工具.zip

    Apache Log4j 2存在远程代码执行漏洞处置指南 及期检测工具

    Apache Log4j 2 源代码( apache-log4j-2.17.1-src.zip)

    Apache Log4j 2 源代码( apache-log4j-2.17.1-src.zip) 是对 Log4j 的升级,它比其前身 Log4j 1.x 提供了重大改进,并提供了 Logback 中可用的许多改进,同时修复了 Logback 架构中的一些固有问题。修复了安全漏洞...

    Pro Apache Log4j second edition

    Pro Apache Log4j second edition Pro Apache Log4j second edition Pro Apache Log4j second edition Pro Apache Log4j second edition Pro Apache Log4j second edition

    apache log4j使用大全

    apache log4j使用大全 log4j使用

    Log4j日志包

    log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender log4j.appender.CONSOLE.Target=System.out log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout log4j.appender.CONSOLE.layout....

    org.apache.log4j

    Log4j是Apache的一个开放源代码项目,通过使用Log4j,我们可以控制日志信息输送的目的地是控制台、文件、GUI组件、甚至是套接口服务器、NT的事件记录器、UNIX Syslog守护进程等;我们也可以控制每一条日志的输出格式...

    apache-log4j-2.16.0-bin.rar

    开源日志框架Apache Log4j2远程代码执行漏洞升级包

    apache-log4j-2.0-rc1-src

    apache-log4j-2.0-rc1-src,开发工程进行用log4j进行日志记录,log4j-2.0的源码

Global site tag (gtag.js) - Google Analytics