<code>
# For JBoss: Avoid to setup Log4J outside $JBOSS_HOME/server/default/deploy/log4j.xml!
# For all other servers: Comment out the Log4J listener in web.xml to activate Log4J.
log4j.rootLogger=INFO, stdout, logfile, DATABASE
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] – %m%n
log4j.appender.logfile=org.apache.log4j.RollingFileAppender
log4j.appender.logfile.File=${catalina.base}/logs/configPro.log
log4j.appender.logfile.MaxFileSize=512KB
# Keep three backup files.
log4j.appender.logfile.MaxBackupIndex=3
# Pattern to output: date priority [category] – message
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern=%d %p [%c] – %m%n
# connection to MS SQL
log4j.appender.DATABASE=org.apache.log4j.jdbc.JDBCAppender
log4j.appender.DATABASE.URL=jdbc:jtds:sqlserver://192.168.3.27:6677/wireless
log4j.appender.DATABASE.driver=net.sourceforge.jtds.jdbc.Driver
log4j.appender.DATABASE.user=user
log4j.appender.DATABASE.password=password
log4j.appender.DATABASE.bufferSize=0
#log4j.appender.DATABASE.sql=INSERT INTO LOG4J (Message) VALUES (‘[framework] %d – %c -%-4r [%t] %-5p %c %x – %m%n’)
log4j.appender.DATABASE.sql=INSERT INTO tb_configPro_log (userID,opDate,remoteIP,requestURL,parameters) VALUES (‘%X{userID}’,’%X{opDate}’,’%X{remote}’,’%X{url}’,’%X{params}’)
log4j.appender.DATABASE.layout=org.apache.log4j.PatternLayout
log4j.appender.DATABASE.layout.ConversionPattern=[framework] %d – %c -%-4r [%t] %-5p %c %x – %m%n
</code>
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.MDC;
//用来向log4j中填数据的
MDC.put(“remote”, request.getRemoteHost());
MDC.put(“userID”, user.getId());
MDC.put(“opDate”, MadUtil.getCurrentTimestamp());
MDC.put(“url”, url);
MDC.put(“params”, pv.toString());
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/100634.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...