java web 工程 log4j 不同模块日志输出到不同文件中

WEB工程中Log4j配置,实现不同模块日志输入到不同文件中。
log4j.rootCategory=info,stdout
log4j.addivity.org.apache=true

log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
log4j.appender.file.File=E\:\\Program Files\\apache-tomcat-6.0.39\\logs\\parkour\\info.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d-[TS] %p %t %c - %m%n

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%p\:%d{yyyyMMdd HH\:mm\:ss} %c\: %m%n

#########自定义日志输出##########

##register模块输出 ## 
log4j.logger.register=INFO,register
log4j.appender.register=org.apache.log4j.DailyRollingFileAppender
log4j.appender.register.File=E\:\\Program Files\\apache-tomcat-6.0.39\\logs\\parkour\\register.log
log4j.appender.register.layout=org.apache.log4j.PatternLayout
log4j.appender.register.layout.ConversionPattern=%d %p [%c] - %m%n
log4j.additivity.register=false

##login模块输出 ##  
log4j.logger.login=INFO,login
log4j.appender.login=org.apache.log4j.DailyRollingFileAppender
log4j.appender.login.File=E\:\\Program Files\\apache-tomcat-6.0.39\\logs\\parkour\\login.log
log4j.appender.login.layout=org.apache.log4j.PatternLayout
log4j.appender.login.layout.ConversionPattern=%d %p [%c] - %m%n
log4j.additivity.login=false

# logger for spring
log4j.logger.org.springframework=error

# logger for MemCached
log4j.logger.com.danga.MemCached=error

# logger for c3p0
log4j.logger.com.mchange=error


org.apache.commons.httpclient=error

org.apache.http=error


Java 代码,LogUtils.java 日志工具类
package com.mrkj.utils;
import org.apache.log4j.Logger;
import com.mrkj.model.ParkourUser;

public class LogUtils {

private static final Logger file = Logger.getLogger("file");
private static final Logger register = Logger.getLogger("register");
private static final Logger login = Logger.getLogger("login");
private static final Logger goldcoin = Logger.getLogger("goldcoin");
private static final Logger recharge = Logger.getLogger("recharge");

public void logInfo(String log) {
file.info(log);
}

public static void registerInfo(ParkourUser user) {
register.info("[register] " + user.getPhoneserial() + "," + user.getCreatetime());
}


public static void loginInfo(ParkourUser user) {
login.info("[login] " + user.getId() + "," + user.getUsername() + "," + user.getPhoneserial() + ","
+ user.getCurrGolden() + "," + user.getCreatetime() + "," + System.currentTimeMillis());
}

}

你可能感兴趣的:(后端)