b735bcc1d14b94036104ee25775d53fbb3b15ee9.svn-base 1.22 KB
package org.activiti.tracelog;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ActivitiLog {
	private static Logger logger = LoggerFactory.getLogger(ActivitiLog.class);
	
	public static final ThreadLocal<Boolean> batchProcessThread = new ThreadLocal<Boolean>();

	public static void debug(String info) {
		if (logger.isDebugEnabled() && (batchProcessThread.get()==null || !batchProcessThread.get())) {
			logger.debug(CurrentLineInfo.getClassName()+"."+CurrentLineInfo.getMethodName()+"[line:"+CurrentLineInfo.getLineNumber()+"]:"+info);
		}
	}
	
	public static boolean isTraceDebug(){
		return logger.isDebugEnabled();
	}

	static class CurrentLineInfo {
		private static final int originStackIndex = 3;

		public static String getFileName() {
			return Thread.currentThread().getStackTrace()[originStackIndex].getFileName();
		}

		public static String getClassName() {
			return Thread.currentThread().getStackTrace()[originStackIndex].getClassName();
		}

		public static String getMethodName() {
			return Thread.currentThread().getStackTrace()[originStackIndex].getMethodName();
		}

		public static int getLineNumber() {
			return Thread.currentThread().getStackTrace()[originStackIndex].getLineNumber();
		}
	}

}