原贴:https://blog.csdn.net/wangchengaihuiming/article/details/95313482
package lct.conference.util; import com.imon.util.Encode; import org.dom4j.Document; import org.dom4j.DocumentException; import org.dom4j.DocumentHelper; import org.dom4j.io.OutputFormat; import org.dom4j.io.XMLWriter; import org.slf4j.LoggerFactory; import org.slf4j.spi.LocationAwareLogger; import sun.misc.JavaLangAccess; import sun.misc.SharedSecrets; import java.io.IOException; import java.io.StringWriter; public class PCMSLog { /**空数组*/ private final Object[] EMPTY_ARRAY = new Object[] {}; /**全类名*/ private final String FQCN = PCMSLog.class.getName(); private LocationAwareLogger pcmslg; private PCMSLog(){ } public static PCMSLog getlog() { PCMSLog pcmsLog=new PCMSLog(); pcmsLog.pcmslg= getLocationAwareLogger(2); return pcmsLog; } public void info(Object obj){ pcmslg.log(null, FQCN, LocationAwareLogger.INFO_INT, obj.toString(), EMPTY_ARRAY, null); } public void info(Object obj,Throwable t){ pcmslg.log(null, FQCN, LocationAwareLogger.INFO_INT, obj.toString(), EMPTY_ARRAY, t); } public void error(Object obj){ if(obj instanceof Throwable){ error(((Throwable)obj).getMessage(),((Throwable)obj)); }else if(obj instanceof String){ pcmslg.log(null, FQCN, LocationAwareLogger.ERROR_INT, obj.toString(), EMPTY_ARRAY, null); } } public void error(String msg,Throwable t){ pcmslg.log(null, FQCN, LocationAwareLogger.ERROR_INT, msg, EMPTY_ARRAY, t); } public void debug(Object obj){ pcmslg.log(null, FQCN, LocationAwareLogger.DEBUG_INT, obj.toString(), EMPTY_ARRAY, null); } }