package com.iamberry.app.tool.log;

import org.apache.log4j.Logger;

/**
 * desc:平台日志
 */
public class RatFWLogger {	
	
	private static String delimiter = " >> ";
	
	private Logger logger = null;
	
	private String appId;

	public RatFWLogger() {
		System.out.println("Ok");
	}
	
	public RatFWLogger(String appId) {
		this.appId = appId;
		logger = Logger.getLogger(appId);
	}
	
	/** 通过Spring IoC注入 
	 * @param 应用系统ID
	 **/
	public void setAppId(String appId) {
		this.appId = appId;
		logger = Logger.getLogger(appId);		
	}	
	
	public void info(String msg) {
		info(null, msg);
	}
	
	public void info(Object sender, String msg) {
		if(logger.isInfoEnabled())
			logger.info(buildMessage(sender,msg));
	}
	
	public void debug(Object sender, String msg) {
		if(logger.isDebugEnabled())
			logger.debug(buildMessage(sender, msg));
	}
	
	public void warn(Object sender, String msg) {
		logger.warn(buildMessage(sender, msg));
	}
	
	public void error(Object sender, String msg)
	{	
		logger.error(buildMessage(sender, msg));
	}
	
	private String buildMessage(Object sender, String message) {
		StringBuffer msg = new StringBuffer();
		if(sender == null)
			msg.append(appId);			
		else
			msg.append(sender.getClass().getName());		 
		msg.append(delimiter).append(message);
		return msg.toString();
	}	
	
}
