Configuring log4j

Configuring log4j typically involes assigning level objects, defining appender objects, and specifying Layout objects.

  • naming and placing the configuation file

By default, the LogManager class will look for a file named log4j.properties or log4j.xml in the classpath used for loading the log4j classes.

If you decide to name your configuation file differently, you are free to do that. However you have to let the log4j framework know by supplying  a command line argument as follows:

-Dlog4j.cofinguation="file_name".

# define the root logger with two appenders writing to console and file
log4j.rootLogger = DEBUG, CONSOLE, FILE
#define your own logger named com.foo
#and assign level and appender to your own logger
log4j.logger.com.foo=DEBUG,FILE
#define the appender named FILE
log4j.appender.FILE=org.apache.log4j.FileAppender
log4j.appender.FILE.File=${user.home}/log.out
#define the appender named CONSOLE
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.conversionPattern=%m%n

notable points about Configuration

  • the configuation file is case-sensive
  • a few of appenders can be only configured through an XMl file
  • some advanced controls, such as Filter and ObjectRender, can be configured only via an XML file.
时间: 2024-07-31 21:54:26

Configuring log4j的相关文章

Log4j – Configuring Log4j 2 - Apache Log4j 2

Apache Log4j 2 ? Logging Wiki Apache Logging Services Sonar   Configuration Inserting log requests into the application code requires a fair amount of planning and effort. Observation shows that approximately 4 percent of code is dedicated to logging

commons-logging log4j的联系区别

1.Apache通用日志接口(commons-logging.jar)介绍 Apache Commons包中的一个,包含了日志功能,必须使用的jar包.这个包本身包含了一个Simple Logger,但是功能很弱.在运行的时候它会先在CLASSPATH找log4j,如果有,就使用log4j,如果没有,就找JDK1.4带的 java.util.logging,如果也找不到就用Simple Logger.commons-logging.jar的出现是一个历史的的遗留的遗憾,当初Apache极力游说S

commons-logging和log4j

1.Apache通用日志接口(commons-logging.jar)介绍 Apache Commons包中的一个,包含了日志功能,必须使用的jar包.这个包本身包含了一个Simple Logger,但是功能很弱.在运行的时候它会先在CLASSPATH找log4j,如果有,就使用log4j,如果没有,就找JDK1.4带的 java.util.logging,如果也找不到就用Simple Logger.commons-logging.jar的出现是一个历史的的遗留的遗憾,当初Apache极力游说S

asynchronous-logging-with-log4j-2--转

原文地址:https://dzone.com/articles/asynchronous-logging-with-log4j-2 Log4J 2 is a logging framework designed to address the logging requirements of enterprise applications. If you are new to Log4J2, I suggest going through my introductory post on Log4J

编程式事务--使用PlatformTransactionManager接口实现事务

软件152 彭梦月 在spring里事务管理有两种实现方式,一个是编程式事务,一个是声明式事务.先从编程式事务开始讲起. 1.java工程的目录结构: 2.首先是applicationContext.xml配置文件,代码如下: <?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns

Sqoop2安装记录

我是采用的源码编译的包安装的, 主要是考虑到会对部分功能做裁剪或增强, 具体源码编译方式可以参考另外一篇博文<编译Sqoop2错误解决>.然后从dist/target目录下拷贝sqoop-1.99.3.tar.gz压缩包的内容到/usr/lib/sqoop目录中. 接下来便是开始对相关配置文件进行配置,注意sqoop2是区分了server和client端的,我们首先安装服务端,记得服务端需要安装到可以执行hadoop命令行的机器上,最直接的方式就是安装到hadoop集群某个节点上,而客户端可以

apache sqoop1.99.3+hadoop2.5.2+mysql5.0.7环境构筑以及数据导入导出

概要 为了调查hadoop生态圈里的制品,特地的了解了一下RDBMS和hdfs之间数据的导入和导出工具,并且调查了一些其他同类的产品,得出来的结论是:都是基于sqoop做的二次开发或者说是webUI包装,实质还是用的sqoop.比如pentaho的PDI,Oracle的ODI,都是基于此,另外,Hortnetwork公司的sandbox,Hue公司的Hue webUI,coulder的coulder manger,做个就更不错了,差不多hadoop下的制品都集成了,部署也不是很复杂,还是很强大的

Android应用中添加Log4j的示例

1.新建Android项目 Project: AndroidLog4j Package:cn.darkranger.log Activity:MainActivity 2.在libs中添加log4j-1.2.17.jar包 3.添加android-logging-log4j-1.0.3.jar 我看了一下,这里面只有两个类,我就用反编译工具反编译成了java文件,写入代码中了 LogCatAppender.java(主要作用是将log在控制台的输出转化为Android中的LogCat输出) pa

java springmvc Log4j filter等(稍微完善一下项目)

仅供参考-接上文 springmvc  1.设置Log4jConfigListener日志监听(可以为开发调试.发布后运行的意外调试.等) 在src/main/resources目录下新建log4j.properties文件(可以在别的目录),这些配置内容网上有很多, # This is the configuring for logging displayed in the Application Server log4j.rootCategory=error, stdout, logfile