log4j指定的接口输出到指定的目标
spring-mvc.xml
<!-- extends HandlerInterceptorAdapter --> <mvc:interceptors> <bean class="com.snailteam.game.controller.TrackHandler"></bean> </mvc:interceptors>
package com.snailteam.game.controller; import java.util.Enumeration; import java.util.HashMap; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; public class TrackHandler extends HandlerInterceptorAdapter { protected final Log logger = LogFactory.getLog(getClass()); @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { Map<String, String> header = new HashMap<String, String>(); Enumeration<String> hs = request.getHeaderNames(); while (hs.hasMoreElements()) { String h = hs.nextElement(); header.put(h, request.getHeader(h)); } logger.info(header); return super.preHandle(request, response, handler); } }
log4j
# Rules reminder: # DEBUG < INFO < WARN < ERROR < FATAL # Global logging configuration log4j.rootLogger=DEBUG,INFO,ERROR,stdout,file ## Console output... log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} - [ %p ] %l - %m%n log4j.appender.stdout.Encoding=UTF-8 # append to file Info log4j.appender.infoFile.Threshold=INFO log4j.appender.infoFile=org.apache.log4j.RollingFileAppender log4j.appender.infoFile=org.apache.log4j.DailyRollingFileAppender log4j.appender.infoFile.Encoding=UTF-8 log4j.appender.infoFile.File=log/game.log log4j.appender.infoFile.DatePattern='_'yyyyMMdd'.log' log4j.appender.infoFile.layout=org.apache.log4j.PatternLayout log4j.appender.infoFile.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} - [ %p ] %l - %m%n # append to file error log4j.appender.errorFile.Threshold=ERROR log4j.appender.errorFile=org.apache.log4j.RollingFileAppender log4j.appender.errorFile=org.apache.log4j.DailyRollingFileAppender log4j.appender.errorFile=org.apache.log4j.FileAppender log4j.appender.errorFile.File=log/game-error.log log4j.appender.errorFile.DatePattern='_'yyyyMMdd'.log' log4j.appender.errorFile.Append=true log4j.appender.errorFile.layout=org.apache.log4j.PatternLayout log4j.appender.errorFile.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} - [ %p ] %l - %m%n #log4j.logger.freemarker=debug log4j.appender.mongodb.layout=org.apache.log4j.PatternLayout log4j.appender.mongodb.layout.ConversionPattern=%m%n log4j.appender.mongodb=org.log4mongo.MongoDbAppender log4j.appender.mongodb.databaseName=logdb log4j.appender.mongodb.Append=true log4j.appender.mongodb.collectionName=loginfo log4j.appender.mongodb.hostname=192.168.1.246 log4j.appender.mongodb.port=9007 log4j.appender.mongodb.writeConcern=FSYNCED # com.snailteam.game.controller.TrackHandler >>> accessFile log4j.appender.accessFile=org.apache.log4j.RollingFileAppender log4j.appender.accessFile=org.apache.log4j.DailyRollingFileAppender log4j.appender.accessFile.Encoding=UTF-8 log4j.appender.accessFile.File=log/accessFile.log log4j.appender.accessFile.DatePattern='_'yyyyMMdd'.log' log4j.appender.accessFile.layout=org.apache.log4j.PatternLayout log4j.appender.accessFile.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} - [ %p ] %l - %m%n log4j.additivity.com.snailteam.game.controller.TrackHandler=false log4j.logger.com.snailteam.game.controller.TrackHandler=debug,accessFile log4j.logger.org.springframework=debug log4j.logger.com.snailteam.game=info, infoFile,errorFile
相关推荐
chw0 2020-11-04
大唐帝国前营 2020-08-18
sdaq 2020-07-26
MrLiar 2020-07-07
sdaq 2020-06-16
CXC0 2020-06-14
丨Fanny丨Cri 2020-06-13
CXC0 2020-06-08
dongxurr 2020-06-07
sdaq 2020-06-06
MrLiar 2020-06-04
丨Fanny丨Cri 2020-06-03
MrLiar 2020-05-25
丨Fanny丨Cri 2020-05-17
MrLiar 2020-05-14
MrLiar 2020-05-12
sdaq 2020-05-11