package com.develop.web.util;
import java.util.concurrent.locks.ReentrantLock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class LogUtil{
private static final String utilClass = LogUtil.class.getName();
private static Logger logger = null;
public static Logger getLogger() {
StackTraceElement[] stacks = Thread.currentThread().getStackTrace();
int depath = 0;
if(stacks!=null&&stacks.length>0){
for(int i=0;i<stacks.length;i++){
if(utilClass.equals(stacks[i].getClassName())){
depath = i+1;
break;
}
}
}
if(depath<stacks.length){
String className = stacks[depath].getClassName();
ReentrantLock lock = new ReentrantLock();
lock.lock();
try {
logger = LoggerFactory.getLogger(className);
} catch (Exception e) {
e.printStackTrace();
} finally {
lock.unlock();
}
}
return logger;
}
}