1.创建commons-logging的配置文件commons-logging.properties置于代码的根目录下,并指定使用Log4J的Logger
org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger
2.创建Log4J的配置文件log4j.properties置于代码的根目录下
#using log4j 1.2.x
#root Logger for all class
log4j.rootLogger=DEBUG,console,logfile
#Logger for specific class
#log4j.logger.common.Log4J=DEBUG,console,logfile
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.Target=System.out
log4j.appender.console.Encoding=GBK
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d %p [%F] [%t] [line %L in %c] - %m%n
#this type of Appender will create log file everyday
log4j.appender.logfile=org.apache.log4j.DailyRollingFileAppender
log4j.appender.logfile.DatePattern='.'yyyy-MM-dd
log4j.appender.logfile.File=logs/testLog.log
log4j.appender.logfile.Append=true
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern=%d %p [%F] [%t] [%L] [%c] - %m%n
# %d = time
# %p = level
# %F = class name
# %t = method name
# %L = line number in class
# %c = class name(include package)
# %m = message
# %n = new line
3.测试代码
package common;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class Log4J {
private static Log logger = LogFactory.getLog(Log4J.class);
/**
* @param args
*/
public static void main(String[] args) {
if(logger.isInfoEnabled())logger.info("this is message");
logger.error("error");
System.out.println("hello");
}
}
分享到:
相关推荐
pax-logging-log4j2 (log4J2) pax-logging-logback (logback) pax-logging-log4j1在 2.0.0 版本之前被命名为pax-logging-service 。 不同的日志 API 基本接口org.osgi.service.log.LogService从OSGi的纲要规范的第...
lib/slf4j-log4j12-1.7.21.jar lib/mybatis-ehcache-1.0.3.jar lib/mybatis-spring-1.3.0.jar lib/spring-aop-4.3.3.RELEASE.jar lib/spring-aspects-4.3.3.RELEASE.jar lib/spring-beans-4.3.3.RELEASE.jar ...
ActiveMQ与Spring线程池整合的一个实例。 lib库没有上传。 ... lib中包含: apache-activemq-4.1.1.jar backport-util-concurrent-2.1.jar ...log4j-1.2.14.jar spring-2.0.jar xbean-spring-2.8.jar
2.commons-logging-1.1.1.jar(ASF出品的日志包,struts2 2、spring、hibernate框架使用这个日志包来支持Log4J和JDK 1.4+的日志记录) 3.common-annotations.jar(支持注解的包) 4.aspectjrt.jar(支持AOP的包) 5....
20020414.jar,slf4j-api-1.5.8.jar,slf4j-log4j12-1.5.8.jar,spring-aop-3.0.7.RELEASE.jar,spring-asm-3.0.7.RELEASE.jar,spring-beans-3.0.7.RELEASE.jar,spring-context-3.0.7.RELEASE.jar,spring-core-3.0.7....
2.commons-logging-1.1.1.jar(ASF出品的日志包,struts2 2、spring、hibernate框架使用这个日志包来支持Log4J和JDK 1.4+的日志记录) 3.common-annotations.jar(支持注解的包) 4.aspectjrt.jar(支持AOP的包) 5....
2.commons-logging-1.1.1.jar(ASF出品的日志包,struts2 2、spring、hibernate框架使用这个日志包来支持Log4J和JDK 1.4+的日志记录) 3.common-annotations.jar(支持注解的包) 4.aspectjrt.jar(支持AOP的包) 5....
所有的日志配置文件放在src目录下,编译时随同.class文件一同拷贝到目录下,这些配置文件必须采用properties文件的编写方法,commons-logging.properties文件用来指定commons-logging的实现为log4j,log4j....
最后,将下载的 Spring Framework 解压,并将其中的 spring.jar、commons-logging.jar 和 log4j-1.2.15.jar 复制到“D:\java\Spring\lib”目录中,然后在 Eclipse 中建立一个“Springlib”库,将三个文件添加进...
kettle依赖于多个jar包,包括kettle-core.jar、kettle-engine.jar、kettle-db.jar、commons-vfs.jar、commons-logging.jar、log4j.jar等。这些jar包可以从kettle官网下载或从maven仓库中获取。 结论 Java代码调用...
protected static org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(ScpClient.class); static private ScpClient instance; private Connection conn; static synchronized public ...
commons-logging.jar flex-messaging-common.jar flex-messaging-core.jar flex-messaging-proxy.jar flex-messaging-remoting.jar 在 web.xml 中添加 HttpFlexSession 和 Servlet 映射。HttpFlexSession ...
外部依赖Commons Logging, (Log4J)。 spring-beans.jar(必须):这 个jar 文件是所有应用都要用到的,它包含访问配置文件、创建和管理bean 以及进行Inversion of Control / Dependency Injection(IoC/DI)操作...
commons-logging.jar flex-messaging-common.jar flex-messaging-core.jar flex-messaging-proxy.jar flex-messaging-remoting.jar 在 web.xml 中添加 HttpFlexSession 和 Servlet 映射。...