ActivitiLog.java 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();
		}
	}

}