public class LogUtil {
private static final Logger log = LoggerFactory
.getLogger(LogUtil.class);
private static final int PROCESS_TOTAL_LENGTH = 150;
private static final String PROCESS_FILL_FLAG = "*";
//DEBUG级别:方法执行开始日志输出,入参为需要打印的方法入参
public static void getMethodStartLog(Map<String,Object> objects){
if(!log.isInfoEnabled()){
return;
}
String clazz = Thread.currentThread() .getStackTrace()[2].getClassName();
String method = Thread.currentThread() .getStackTrace()[2].getMethodName();
String out = clazz+" "+method+" is starting";
StringBuffer sb = new StringBuffer();
int outLength = out.length();
int start = (PROCESS_TOTAL_LENGTH - outLength)/2;
int end = 0;
if(outLength%2==0){
end = (PROCESS_TOTAL_LENGTH - outLength)/2;
}else{
end = (PROCESS_TOTAL_LENGTH - outLength)/2+1;
}
for(int i=0;i<start;i++){
sb.append(PROCESS_FILL_FLAG);
}
out = sb.toString()+out;
sb = new StringBuffer();
for(int i=0;i<end;i++){
sb.append(PROCESS_FILL_FLAG);
}
out = out+sb.toString();
log.debug(out);
if(objects !=null){
for (Map.Entry<String, Object> m :objects.entrySet()) {
log.debug("inMethod parameter["+m.getKey()+"] is : ");
log.debug(m.getValue()+"");
}
}
}
//DEBUG级别:方法执行结束日志输出,入参为需要打印的方法输出,process级别的方法
public static void getMethodEndLog(Map<String,Object> objects){
if(!log.isInfoEnabled()){
return;
}
String clazz = Thread.currentThread() .getStackTrace()[2].getClassName();
String method = Thread.currentThread() .getStackTrace()[2].getMethodName();
String out = clazz+" "+method+" is end";
StringBuffer sb = new StringBuffer();
int outLength = out.length();
int start = (PROCESS_TOTAL_LENGTH - outLength)/2;
int end = 0;
if(outLength%2==0){
end = (PROCESS_TOTAL_LENGTH - outLength)/2;
}else{
end = (PROCESS_TOTAL_LENGTH - outLength)/2+1;
}
for(int i=0;i<start;i++){
sb.append(PROCESS_FILL_FLAG);
}
out = sb.toString()+out;
sb = new StringBuffer();
for(int i=0;i<end;i++){
sb.append(PROCESS_FILL_FLAG);
}
out = out+sb.toString();
if(objects !=null){
for (Map.Entry<String, Object> m :objects.entrySet()) {
log.debug("inMethod parameter["+m.getKey()+"] is : ");
log.debug(m.getValue()+"");
}
}
log.debug(out);
}
@Deprecated
public static void getMethodDebugProcessLog(String msg){
if(!log.isDebugEnabled()){
return;
}else{
log.debug(msg);
}
}
共同学习,写下你的评论
评论加载中...
作者其他优质文章