Commit de7369bb by fukai

补充异常日志记录

parent 43d217c9
......@@ -213,6 +213,13 @@ public class NoUiPresentation extends AbstractNullPresentation {
public boolean message(MessageType paramMessageType, String paramString, Object paramObject) throws ContainerException {
if(paramMessageType.equals(MessageType.ERROR) && (paramObject instanceof Throwable))
{
//记录异常日志
TxInfo.recordException((Throwable)paramObject);
}
String str1 = "";
try {
if ((paramObject instanceof String)) {
......
package org.sss.presentation.noui.context;
import log.Log;
import log.LogFactory;
import org.apache.commons.io.IOUtils;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.engine.spi.SessionImplementor;
import org.sss.module.hibernate.HibernateUtils;
import org.sss.module.pojo.DatabaseUtils;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.Date;
import java.util.Optional;
import java.util.stream.Stream;
public class TxInfo {
protected static final Log log = LogFactory.getLog(TxInfo.class);
public static ThreadLocal<TxInfo> txInfoHolder = new ThreadLocal<>();
public String txCode;
public String url;
public String target;
public static void putTxInfo(String txCode,String url,String target)
{
TxInfo txInfo = new TxInfo();
txInfo.txCode = txCode;
txInfo.url = url;
txInfo.target = target;
txInfoHolder.set(txInfo);
}
public static TxInfo getTxInfo()
{
return txInfoHolder.get();
}
public static void releaseCurrTxInfo()
{
txInfoHolder.remove();
}
/**
* 记录异常信息
* @param e
*/
public static void recordException(Throwable e) {
TxInfo txInfo = getTxInfo();
Session session = HibernateUtils.openSession(null);
long count = DatabaseUtils.executeCounter(((SessionImplementor) session).connection(),"dealog");
String inr = String.format("%08d",count);
Transaction transaction = session.beginTransaction();
SQLQuery sqlQuery = session.createSQLQuery("insert into dealog(INR,CREDATTIM,SRVCOD,SRVNAM,INIFRM,RTNMSG,LOGLEV) values(?,?,?,?,?,?,?)");
sqlQuery.setString(0,inr);
sqlQuery.setTimestamp(1,new Date());
String srvcod = txInfo.url.replace("/_","-");
sqlQuery.setString(2,srvcod);
sqlQuery.setString(3,srvcod);
sqlQuery.setString(4,txInfo.txCode);
sqlQuery.setString(5,genMessage(e));
sqlQuery.setString(6,"error");
sqlQuery.executeUpdate();
transaction.commit();
session.close();
log.debug("完成异常日志记录");
}
private static String genMessage(Throwable e)
{
while(e.getCause() != null)
e = e.getCause();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(bos);
e.printStackTrace(ps);
String mesg = bos.toString();
IOUtils.closeQuietly(ps);
IOUtils.closeQuietly(bos);
String[] lines = mesg.split("[\r\n]{1,2}");
Optional<String> rs = Stream.of(lines).filter(str->{
return str.charAt(0) != '\t' || (str.indexOf("brilliance")>0 || str.indexOf(".noui.")>0);
}).reduce((acc,item)->{
return acc+'\n'+item;
});
return rs.get();
}
}
......@@ -19,6 +19,7 @@ import org.sss.presentation.noui.common.Constants;
import org.sss.presentation.noui.context.NoUiContext;
import org.sss.presentation.noui.context.NoUiContextManager;
import org.sss.presentation.noui.context.NoUiPresentation;
import org.sss.presentation.noui.context.TxInfo;
import org.sss.presentation.noui.jwt.RedisLoginInfo;
import org.sss.presentation.noui.util.DataSecurityUtil;
import org.sss.presentation.noui.util.NoUiPresentationUtil;
......@@ -59,6 +60,9 @@ public abstract class AbstractCommonController {
Alias alias = new Alias(mappingUrl);
String trnName = alias.getTrnName();
putTxInfo(alias,mappingUrl);//记录交易信息
Map<String, ?> paramsMap = noUiRequest.getParamsMap();
context = NoUiContextManager.createNoUiContext(noUiRequest);
......@@ -177,19 +181,29 @@ public abstract class AbstractCommonController {
ret = ResultUtil.result(NoUiPresentationUtil.retCode(context), NoUiPresentationUtil.retMsg(context), afterReturnData,paginationData,
NoUiPresentationUtil.handleErrorReturnData(context, alias), NoUiPresentationUtil.handleCodeTableReturnData(context, alias), noUiVersion.getVersion());
} catch (Exception e) {
} catch (Throwable e) {
log.error("OnClick command error", e);
ret = ResultUtil.result(ErrorCodes.ERROR, "hander error", "service error", noUiVersion.getVersion());
TxInfo.recordException(e);
} finally {
if (context != null) {
//context.getSupport().disconnect();
context.dispose();
}
TxInfo.releaseCurrTxInfo();
}
return ret;
}
private void putTxInfo(Alias alias,String mappingUrl)
{
String trnName = alias.getTrnName();
String aliasActionUrl = alias.getAliasActionUrl();
String actionUrl = alias.getRel().get(aliasActionUrl);
TxInfo.putTxInfo(trnName,mappingUrl,actionUrl);
}
private IBaseObject baseObject(NoUiContext context, NoUiRequest noUiRequest, Alias alias) {
String aliasActionUrl = alias.getAliasActionUrl();
String actionUrl = alias.getRel().get(aliasActionUrl);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment