Commit c7202cb3 authored by Quxl's avatar Quxl

x

parent 9cbdd74b
...@@ -37,8 +37,15 @@ public class AliyunLogProducer { ...@@ -37,8 +37,15 @@ public class AliyunLogProducer {
private static final ExecutorService EXECUTOR_SERVICE = Executors.newCachedThreadPool(); private static final ExecutorService EXECUTOR_SERVICE = Executors.newCachedThreadPool();
public void sendLog(String logText) { public void sendLog(String logText) {
if(!isOpen) {
return;
}
try { try {
List<LogItem> logItems = new ArrayList<LogItem>(); List<LogItem> logItems = new ArrayList<LogItem>();
LogItem logItem = new LogItem();
logItem.PushBack("id", String.valueOf(System.currentTimeMillis()));
logItem.PushBack("logText", logText);
logItems.add(logItem);
ListenableFuture<Result> future = producer.send(project, logStore, logItems); ListenableFuture<Result> future = producer.send(project, logStore, logItems);
Futures.addCallback(future, new SampleFutureCallback(project, logStore, logText), EXECUTOR_SERVICE); Futures.addCallback(future, new SampleFutureCallback(project, logStore, logText), EXECUTOR_SERVICE);
} catch (Exception e) { } catch (Exception e) {
......
...@@ -5,19 +5,26 @@ import javax.servlet.http.HttpServletResponse; ...@@ -5,19 +5,26 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver; import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.json.MappingJackson2JsonView; import org.springframework.web.servlet.view.json.MappingJackson2JsonView;
import com.egolm.common.bean.Rjx; import com.egolm.common.bean.Rjx;
import com.egolm.shop.aliyunLog.AliyunLogProducer;
import com.egolm.shop.util.I18NUtils; import com.egolm.shop.util.I18NUtils;
import io.netty.util.internal.ThrowableUtil;
@Component @Component
public class ExceptionHandler implements HandlerExceptionResolver { public class ExceptionHandler implements HandlerExceptionResolver {
private static final Log logger = LogFactory.getLog(ExceptionHandler.class); private static final Log logger = LogFactory.getLog(ExceptionHandler.class);
@Autowired
private AliyunLogProducer logProducer;
@Override @Override
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) { public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
String langID = request.getParameter("langID"); String langID = request.getParameter("langID");
...@@ -33,6 +40,7 @@ public class ExceptionHandler implements HandlerExceptionResolver { ...@@ -33,6 +40,7 @@ public class ExceptionHandler implements HandlerExceptionResolver {
mav.addAllObjects(Rjx.jsonErr().setMessage(I18NUtils.getMessage(langID, "Msg_Exception_processFailure"))); mav.addAllObjects(Rjx.jsonErr().setMessage(I18NUtils.getMessage(langID, "Msg_Exception_processFailure")));
} finally { } finally {
logger.error("", ex); logger.error("", ex);
logProducer.sendLog(ThrowableUtil.stackTraceToString(ex));
} }
return mav; return mav;
} }
......
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