|
|
|
@ -4,6 +4,13 @@ import com.fr.base.io.IOFile;
|
|
|
|
|
import com.fr.base.io.XMLReadHelper; |
|
|
|
|
import com.fr.design.DesignerEnvManager; |
|
|
|
|
import com.fr.design.i18n.Toolkit; |
|
|
|
|
import com.fr.third.apache.logging.log4j.Level; |
|
|
|
|
import com.fr.third.apache.logging.log4j.core.Filter; |
|
|
|
|
import com.fr.third.apache.logging.log4j.core.Layout; |
|
|
|
|
import com.fr.third.apache.logging.log4j.core.LogEvent; |
|
|
|
|
import com.fr.third.apache.logging.log4j.core.appender.AbstractAppender; |
|
|
|
|
import com.fr.third.apache.logging.log4j.core.config.Property; |
|
|
|
|
import com.fr.third.apache.logging.log4j.core.layout.PatternLayout; |
|
|
|
|
import com.fr.web.session.SessionLocalManager; |
|
|
|
|
|
|
|
|
|
import com.fr.stable.StableUtils; |
|
|
|
@ -12,22 +19,20 @@ import com.fr.stable.project.ProjectConstants;
|
|
|
|
|
import com.fr.stable.web.SessionProvider; |
|
|
|
|
import com.fr.stable.xml.XMLPrintWriter; |
|
|
|
|
import com.fr.stable.xml.XMLableReader; |
|
|
|
|
import com.fr.third.apache.log4j.AppenderSkeleton; |
|
|
|
|
import com.fr.third.apache.log4j.Level; |
|
|
|
|
import com.fr.third.apache.log4j.spi.LoggingEvent; |
|
|
|
|
import com.fr.web.core.SessionPoolManager; |
|
|
|
|
import com.fr.web.core.TemplateSessionIDInfo; |
|
|
|
|
import com.fr.workspace.WorkContext; |
|
|
|
|
|
|
|
|
|
import java.io.ByteArrayInputStream; |
|
|
|
|
import java.io.InputStream; |
|
|
|
|
import java.io.Serializable; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 收集设计器报错信息的appender. |
|
|
|
|
* <p> |
|
|
|
|
* Created by Administrator on 2017/7/24 0024. |
|
|
|
|
*/ |
|
|
|
|
public class ErrorInfoLogAppender extends AppenderSkeleton { |
|
|
|
|
public class ErrorInfoLogAppender extends AbstractAppender { |
|
|
|
|
|
|
|
|
|
private static final int ERROR_LEN = 8; |
|
|
|
|
private static final int ERROR_STACK_TRACE = 15; |
|
|
|
@ -38,16 +43,23 @@ public class ErrorInfoLogAppender extends AppenderSkeleton {
|
|
|
|
|
private String uuid; |
|
|
|
|
private String activekey; |
|
|
|
|
|
|
|
|
|
public ErrorInfoLogAppender() { |
|
|
|
|
this.layout = new com.fr.third.apache.log4j.PatternLayout("%d{HH:mm:ss} %t %p [%c] %m%n"); |
|
|
|
|
|
|
|
|
|
protected ErrorInfoLogAppender(String name, Filter filter, |
|
|
|
|
Layout<? extends Serializable> layout, |
|
|
|
|
boolean ignoreExceptions, |
|
|
|
|
Property[] properties) { |
|
|
|
|
super(name, filter, layout, ignoreExceptions, properties); |
|
|
|
|
DesignerEnvManager envManager = DesignerEnvManager.getEnvManager(); |
|
|
|
|
this.username = envManager.getDesignerLoginUsername(); |
|
|
|
|
this.uuid = envManager.getUUID(); |
|
|
|
|
this.activekey = envManager.getActivationKey(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected void append(LoggingEvent event) { |
|
|
|
|
public static ErrorInfoLogAppender createErrorLogAppender() { |
|
|
|
|
return new ErrorInfoLogAppender(ErrorInfoLogAppender.class.getSimpleName(), null, PatternLayout.newBuilder().withPattern("%d{HH:mm:ss} %t %p [%c] %m%n %throwable{0}").build(), false, Property.EMPTY_ARRAY); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void append(LogEvent event) { |
|
|
|
|
this.subAppend(event); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -55,19 +67,12 @@ public class ErrorInfoLogAppender extends AppenderSkeleton {
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public synchronized void close() { |
|
|
|
|
if (this.closed) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
this.closed = true; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void subAppend(LoggingEvent event) { |
|
|
|
|
public void subAppend(LogEvent event) { |
|
|
|
|
Level level = event.getLevel(); |
|
|
|
|
// 只分析上传记录error以上的.
|
|
|
|
|
if (level.isGreaterOrEqual(Level.ERROR)) { |
|
|
|
|
String msg = this.layout.format(event); |
|
|
|
|
if (level.isMoreSpecificThan(Level.ERROR)) { |
|
|
|
|
String msg = (String) this.toSerializable(event); |
|
|
|
|
// 这个id并不是一定会有的, 有就记录下, 说明是预览模板出的错.
|
|
|
|
|
String templateid = readTemplateID(); |
|
|
|
|
String logid = readLogID(msg); |
|
|
|
@ -80,13 +85,13 @@ public class ErrorInfoLogAppender extends AppenderSkeleton {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private String readStackTrace(LoggingEvent event) { |
|
|
|
|
String[] s = event.getThrowableStrRep(); |
|
|
|
|
private String readStackTrace(LogEvent event) { |
|
|
|
|
StackTraceElement[] s = event.getThrown() == null ? null : event.getThrown().getStackTrace(); |
|
|
|
|
StringBuilder sb = new StringBuilder(); |
|
|
|
|
if (s != null) { |
|
|
|
|
int len = Math.min(s.length, ERROR_STACK_TRACE); |
|
|
|
|
for (int i = 0; i < len; i++) { |
|
|
|
|
sb.append(s[i]).append("\n"); |
|
|
|
|
sb.append(s[i].toString()).append("\n"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return sb.toString(); |
|
|
|
|