Commit a07c5ba4 authored by Quxl's avatar Quxl

x

parent ee1a644f
...@@ -30,18 +30,32 @@ public class LogServiceImpl implements LogService { ...@@ -30,18 +30,32 @@ public class LogServiceImpl implements LogService {
@Override @Override
public void saveErrorLog(Throwable ex) { public void saveErrorLog(Throwable ex) {
Fc_logs_error error = new Fc_logs_error();
error.setTitle(ex.getMessage());
error.setError(this.toStackString(ex, 0).toString());
error.setCreate_time(new Date());
jdbcTemplate.save(error);
}
public StringBuffer toStackString(Throwable ex, Integer level) {
StringBuffer stack = new StringBuffer();
if(ex != null) { if(ex != null) {
StringBuffer stack = new StringBuffer(); StringBuffer prefix = new StringBuffer();
stack.append(ex.getMessage()).append("\n"); Integer tmpLevel = (level == null || level < 0) ? 0 : level;
for(int i = 0; i < tmpLevel; i++) {
prefix.append(" ");
}
tmpLevel += 1;
StackTraceElement[] elms = ex.getStackTrace(); StackTraceElement[] elms = ex.getStackTrace();
for(StackTraceElement elm : elms) { for(StackTraceElement elm : elms) {
stack.append(elm.getClassName()).append(".").append(elm.getMethodName()).append("(").append(elm.getFileName()).append(" ").append(elm.getLineNumber()).append(")\n"); stack.append(prefix).append(elm.getClassName()).append(".").append(elm.getMethodName()).append("(").append(elm.getFileName()).append(" ").append(elm.getLineNumber()).append(")\n");
}
stack.append("\n\n\n").append("Cause By: \n").append(this.toStackString(ex.getCause(), tmpLevel));
for(Throwable e : ex.getSuppressed()) {
stack.append("\n\n\n").append("Suppressed By: \n").append(this.toStackString(e, tmpLevel));
} }
Fc_logs_error error = new Fc_logs_error();
error.setError(stack.toString());
error.setCreate_time(new Date());
jdbcTemplate.save(error);
} }
return stack;
} }
} }
...@@ -18,6 +18,9 @@ public class Fc_logs_error implements java.io.Serializable { ...@@ -18,6 +18,9 @@ public class Fc_logs_error implements java.io.Serializable {
private Integer id; private Integer id;
@Column(columnDefinition="text") @Column(columnDefinition="text")
private String title;
@Column(columnDefinition="longtext")
private String error; private String error;
@Column(columnDefinition="datetime") @Column(columnDefinition="datetime")
...@@ -32,6 +35,14 @@ public class Fc_logs_error implements java.io.Serializable { ...@@ -32,6 +35,14 @@ public class Fc_logs_error implements java.io.Serializable {
return id; return id;
} }
public void setTitle(String title) {
this.title = title;
}
public String getTitle() {
return title;
}
public void setError(String error) { public void setError(String error) {
this.error = error; this.error = error;
} }
......
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