org.apache.commons.logging.LogFactory.getLog(LogFactory.class)
common-logging算是各种日志的抽象,可以通过它进行简单的切换来使用不同的log,当然包括log4j.下面看一个具体的例子
配置log4j
默认配置文件名:log4j.properties,放置于classpath下即可。简单配置如下:
更多配置请看 http://www.blogjava.net/kit-soft/archive/2009/08/28/292977.htmllog4j.rootCategory=DEBUG,stdout log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.SimpleLayout
如果想更改配置文件名称或位置,如果在spring下比较简单,web.xml下做如下配置:
<!-- log4j configuration --> <context-param> <param-name>log4jConfigLocation</param-name> <param-value>classpath:log44j.properties</param-value> </context-param> <listener> <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> </listener>
配置common-logging
配置文件common-logging.properties,放在classpath下,内容为:
org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger
代码中这样写:org.apache.commons.logging.LogFactory.getLog(LogFactory.class)