log4j的通用配置和使用

    log4j.properties

 

log4j.rootLogger=INFO,filelog,stdout

log4j.appender.stdout = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target = System.out
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern =%-d{yyyy-MM-dd HH:mm:ss} - [ %p ]  %m%n


log4j.logger.java.sql.Connection = DEBUG  
log4j.logger.java.sql.Statement = DEBUG  
log4j.logger.java.sql.PreparedStatement = DEBUG  
log4j.logger.java.sql.ResultSet = DEBUG
log4j.logger.org.apache=INFO
log4j.logger.com.ibatis = DEBUG  
log4j.logger.com.ibatis.common.jdbc.SimpleDataSource = DEBUG  
log4j.logger.com.ibatis.common.jdbc.ScriptRunner = DEBUG  
log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate = DEBUG  


log4j.appender.filelog = org.apache.log4j.DailyRollingFileAppender
log4j.appender.filelog.File =..//webapps//hello//log//hello.log
log4j.appender.filelog.Append = true
log4j.appender.filelog.DatePattern=.yyyy-MM-dd
log4j.appender.filelog.Threshold = INFO
log4j.appender.filelog.layout = org.apache.log4j.PatternLayout
#log4j.appender.filelog.layout.ConversionPattern = [%d{yyyy-MM-dd HH/:mm/:ss}]%-5p %c(line/:%L) %x%m%n
log4j.appender.filelog.layout.ConversionPattern =[%p]%d{yyyy-MM-dd HH:mm:ss,SSS} [locate]%l [class]%c [out]%m%n

user.log.del=true 
user.time.unit=m
user.time.save=3

    LogUtil.java 

public class LogUtil {

	/**
	 * 调用方式:LogUtil.info(this,"hello");
	 * info
	 * @param obj
	 * @param message
	 */
	public static void info(Object obj,String message){
		Logger log = Logger.getLogger(obj.getClass());
		log.info(message);
	}
	/**
	 * error
	 * @param obj
	 * @param message
	 */
	public static void error(Object obj,String message){
		Logger log = Logger.getLogger(obj.getClass());
		log.error(message);
	}
	/**
	 * debug
	 * @param obj
	 * @param message
	 */
	public static void debug(Object obj,String message){
		Logger log = Logger.getLogger(obj.getClass());
		log.debug(message);
	}
	
	
}

 

 

你可能感兴趣的:(java,log4j)