log4j日志工具类

/**
* log4j日志Util
*/
public class LogUtil {
private static Logger logger=null;

static{
StackTraceElement[] stackTraceElements=new Throwable().getStackTrace();
String callerClassName=stackTraceElements[1].getClassName();
logger=LoggerFactory.getLogger(callerClassName);
}

private LogUtil(){}

//---------------------error---------------------------------
public static void error(String param,String msg,Throwable e){
StackTraceElement se = Thread.currentThread().getStackTrace()[2];
String clazzMethod = " "+se.getClassName() +"." + se.getMethodName() + "("+se.getFileName()+":"+se.getLineNumber()+") ";

String log = clazzMethod+" PARAMS: " +param+" "+" MSG: "+ msg;
logger.error(log,e);
}

//---------------------warn----------------------------------
public static void warn(String param,String msg){
StackTraceElement se = Thread.currentThread().getStackTrace()[2];
String clazzMethod = " "+se.getClassName() +"." + se.getMethodName() + "("+se.getFileName()+":"+se.getLineNumber()+") ";

String log = clazzMethod+" PARAMS: " +param+" "+" MSG: "+ msg;
logger.warn(log);
}

//---------------------info----------------------------------
public static void info(String param,String msg){//
StackTraceElement se = Thread.currentThread().getStackTrace()[2];
String clazzMethod = " "+se.getClassName() +"." + se.getMethodName() + "("+se.getFileName()+":"+se.getLineNumber()+") ";

String log = clazzMethod + " PARAMS: " +param+" "+" MSG: "+ msg;
logger.info(log);
}

public static void debug(String msg) {
StackTraceElement se = Thread.currentThread().getStackTrace()[2];
String clazzMethod = " "+se.getClassName() +"." + se.getMethodName() + "("+se.getFileName()+":"+se.getLineNumber()+") ";

String log = clazzMethod + " MSG: "+ msg;
logger.debug(log);
}

}

posted @ 2017-05-11 18:27  奋小斗g  阅读(389)  评论(0编辑  收藏  举报