Commit 3b48a1d6 authored by yanzg's avatar yanzg

修复异常提醒,从而正确的跟踪异常信息

parent 557d5ee1
...@@ -75,6 +75,8 @@ public class AspectLogResult { ...@@ -75,6 +75,8 @@ public class AspectLogResult {
} else { } else {
responseResult = responseDefault; responseResult = responseDefault;
} }
String fullUrl = String.format("%s:%s", tag, url);
logCountTime.start(fullUrl);
String json = JsonHelper.serialize(responseResult); String json = JsonHelper.serialize(responseResult);
Log.error(cls, resultEx, "%s [ %s ] time %d ms, result: %s", tag, url, time, aspectLogBody.getMaxString(json)); Log.error(cls, resultEx, "%s [ %s ] time %d ms, result: %s", tag, url, time, aspectLogBody.getMaxString(json));
......
...@@ -63,16 +63,15 @@ public class AspectLogStart { ...@@ -63,16 +63,15 @@ public class AspectLogStart {
LogInfoVo log = new LogInfoVo(); LogInfoVo log = new LogInfoVo();
log.setCreateDate(DateHelper.getDateTimeString(new Date())); log.setCreateDate(DateHelper.getDateTimeString(new Date()));
// 写入其他对象 // 写入其他对象
log.setActionKey(tag); log.setApplicationName(this.cloudConfig.getApplicationName());
log.setActionSubKey(String.format("%s:%s", this.cloudConfig.getApplicationName(), url)); log.setTag(tag);
log.setUrl(url);
log.setContent(body); log.setContent(body);
// 生命日志对象爱嗯 // 生命日志对象爱嗯
log.setLogId(StringHelper.getNewID()); log.setLogId(StringHelper.getNewID());
// 开始记录到日志对象中
this.logLocal.startLog(log); this.logLocal.startLog(log);
String fullUrl = String.format("%s:%s", tag, url); // 输出日志
logCountTime.start(fullUrl);
boolean isLog = logFlag && this.cloudConfig.isLogCommon(); boolean isLog = logFlag && this.cloudConfig.isLogCommon();
if (isLog) { if (isLog) {
Log.info(cls, " %s [ %s ] request: %s", tag, url, body); Log.info(cls, " %s [ %s ] request: %s", tag, url, body);
......
package com.yanzuoguang.log; package com.yanzuoguang.log;
import com.yanzuoguang.util.vo.BaseVo;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
public class LogInfoVo extends LogVo { public class LogInfoVo extends BaseVo {
private static final long serialVersionUID = -8629960247077620458L;
/**
* 日志id
*/
@ApiModelProperty(value = "日志Id", required = true, example = "{{$uuid}}")
private String logId;
/**
* 项目名称
*/
@ApiModelProperty(value = "项目名称", required = true)
private String applicationName;
/**
* 触发点
*/
@ApiModelProperty(value = "触发点", required = true, example = "MQ|WEB|FEIGN")
private String tag;
/**
* 请求接口地址
*/
@ApiModelProperty(value = "接口地址", required = true, example = "tbd-order/order/save")
private String url;
/**
* 请求内容
*/
@ApiModelProperty(value = "请求内容", required = true, example = "{}")
private String content;
/**
* 返回参数
*/
@ApiModelProperty(value = "返回结果", required = true, example = "{}")
private String result;
/**
* 接口处理状态,是否有异常
*/
@ApiModelProperty(value = "执行状态", notes = "0表示成功,其他状态表示失败,-1表示执行中", required = true, example = "0")
private int status;
/** /**
* 开始时间 * 开始时间
*/ */
@ApiModelProperty(value = "开始时间", notes = "单位(毫秒)") @ApiModelProperty(value = "开始时间", notes = "单位(毫秒)")
private long start = System.currentTimeMillis(); private long start = System.currentTimeMillis();
/**
* 使用时间
*/
@ApiModelProperty(value = "执行耗时", notes = "单位(毫秒)", required = true, example = "20")
private int useTime;
/**
* 创建时间
*/
@ApiModelProperty(value = "创建时间", notes = "单位(毫秒)", required = false, example = "1987-11-24 23:15:18")
private String createDate;
public String getLogId() {
return logId;
}
public void setLogId(String logId) {
this.logId = logId;
}
public String getApplicationName() {
return applicationName;
}
public void setApplicationName(String applicationName) {
this.applicationName = applicationName;
}
public String getTag() {
return tag;
}
public void setTag(String tag) {
this.tag = tag;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getResult() {
return result;
}
public void setResult(String result) {
this.result = result;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public long getStart() { public long getStart() {
return start; return start;
...@@ -16,4 +119,20 @@ public class LogInfoVo extends LogVo { ...@@ -16,4 +119,20 @@ public class LogInfoVo extends LogVo {
public void setStart(long start) { public void setStart(long start) {
this.start = start; this.start = start;
} }
public int getUseTime() {
return useTime;
}
public void setUseTime(int useTime) {
this.useTime = useTime;
}
public String getCreateDate() {
return createDate;
}
public void setCreateDate(String createDate) {
this.createDate = createDate;
}
} }
...@@ -74,7 +74,7 @@ public class LogLocal implements ThreadNext.Next, InitializingBean { ...@@ -74,7 +74,7 @@ public class LogLocal implements ThreadNext.Next, InitializingBean {
return; return;
} }
// 日志请求不记录,防止死循环递归 // 日志请求不记录,防止死循环递归
boolean isLog = isLog(log.getActionKey(), log.getActionSubKey()); boolean isLog = isLog(log.getTag(), log.getUrl());
if (isLog) { if (isLog) {
this.remove(log); this.remove(log);
} else { } else {
......
package com.yanzuoguang.log;
import com.yanzuoguang.util.vo.BaseVo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
/**
* 日志实例
*
* @author 颜佐光
*/
@ApiModel(value = "日志对象")
public class LogVo extends BaseVo {
private static final long serialVersionUID = -8629960247077620458L;
/**
* 日志id
*/
@ApiModelProperty(value = "日志Id", required = true, example = "{{$uuid}}")
private String logId;
/**
* 工程实例名
*/
@ApiModelProperty(value = "项目名称", required = true, example = "MQ|WEB|FEIGN")
private String actionKey;
/**
* 请求接口地址
*/
@ApiModelProperty(value = "接口地址", required = true, example = "tbd-order/order/save")
private String actionSubKey;
/**
* 请求内容
*/
@ApiModelProperty(value = "请求内容", required = true, example = "{}")
private String content;
/**
* 执行后的请求内容
*/
@ApiModelProperty(value = "执行后的请求内容,仅仅在内容有变化时写入", required = true, example = "{}")
private String contentTo;
/**
* 返回参数
*/
@ApiModelProperty(value = "返回结果", required = true, example = "{}")
private String result;
/**
* 接口处理状态,是否有异常
*/
@ApiModelProperty(value = "执行状态", notes = "0表示成功,其他状态表示失败,-1表示执行中", required = true, example = "0")
private String status;
/**
* 使用时间
*/
@ApiModelProperty(value = "执行耗时", notes = "单位(毫秒)", required = true, example = "20")
private int useTime;
/**
* 创建时间
*/
@ApiModelProperty(value = "创建时间", notes = "单位(毫秒)", required = false, example = "1987-11-24 23:15:18")
private String createDate;
public String getLogId() {
return logId;
}
public void setLogId(String logId) {
this.logId = logId;
}
public String getActionKey() {
return actionKey;
}
public void setActionKey(String actionKey) {
this.actionKey = actionKey;
}
public String getActionSubKey() {
return actionSubKey;
}
public void setActionSubKey(String actionSubKey) {
this.actionSubKey = actionSubKey;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getContentTo() {
return contentTo;
}
public void setContentTo(String contentTo) {
this.contentTo = contentTo;
}
public String getResult() {
return result;
}
public void setResult(String result) {
this.result = result;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public int getUseTime() {
return useTime;
}
public void setUseTime(int useTime) {
this.useTime = useTime;
}
public String getCreateDate() {
return createDate;
}
public void setCreateDate(String createDate) {
this.createDate = createDate;
}
}
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