需求:
日志记录,日志格式化特殊需求化定制,那么需要logback
转载请注明出自:http://snv.iteye.com/
那么logback和spring进行集成开发
jar依赖:
log4j log4j 1.2.16 org.slf4j slf4j-api 1.6.1 org.slf4j jcl-over-slf4j 1.6.1 org.slf4j slf4j-log4j12 1.6.1 ch.qos.logback logback-core 1.0.11 org.logback-extensions logback-ext-spring 0.1.1
spring相关:
org.apache.commons commons-io 1.3.2 org.apache.commons commons-collections4 4.0 org.codehaus.jackson jackson-mapper-lgpl 1.9.13 org.springframework spring-web 3.1.0.RELEASE org.springframework spring-webmvc 3.1.0.RELEASE javax.servlet jstl 1.2 javax.servlet jsp-api 2.0 provided javax.servlet servlet-api 2.5 provided
web.xml:
ch.qos.logback.ext.spring.web.LogbackConfigListener logbackConfigLocation classpath:logback.xml
logback.xml:注意路径
%d{HH:mm:ss.SSS} %-5level %logger{80} - %msg%n D:/logs/debug.%d{yyyy-MM-dd}.log 30 %date [%thread] %-5level %logger{80} - %msg%n
使用:
import org.slf4j.Logger;import org.slf4j.LoggerFactory;public class Test { private Logger log = LoggerFactory.getLogger(UsrController.class); public String login(HttpServletRequest request) { String username = request.getParameter("username"); String password = request.getParameter("password"); log.info("username:{} and pwd:{}", username, password); return null; }}