log4j slf4j 配置
<dependency><groupId>org.slf4j</groupId><artifactId>slf4j-api</artifactId><version>1.6.3</version></dependency>
?
2. 在classpath(src/main/resource)目录下建一个env.properties或log4j.properties文件
### direct log messages to stdout ###log4j.rootLogger=${log4j.rootLogger}log4j.appender.stdout=${log4j.appender.stdout}log4j.appender.stdout.Target=${log4j.appender.stdout.Target}log4j.appender.stdout.layout=${log4j.appender.stdout.layout}log4j.appender.stdout.layout.ConversionPattern=${log4j.appender.stdout.layout.ConversionPattern}
?
3. filter-dev.properties
### direct log messages to stdout ###log4j.rootLogger=info, stdoutlog4j.appender.stdout=org.apache.log4j.ConsoleAppenderlog4j.appender.stdout.Target=System.outlog4j.appender.stdout.layout=org.apache.log4j.PatternLayoutlog4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n
?
4. web.xml中指定log4j的spring配置及listener
<!-- specify log configure file --><context-param><param-name>log4jConfigLocation</param-name><param-value>classpath:env.properties</param-value></context-param><!-- log listener --><listener><listener-class>org.springframework.web.util.Log4jConfigListener</listener-class></listener>
?
5. 在代码中使用
import org.slf4j.Logger;import org.slf4j.LoggerFactory;......private static Logger LOGER = LoggerFactory.getLogger(UserAction.class);...LOGER.info("############ hibernate pagination search user");
?
?
?
?