Browse Source

CORE-116 删除LogRecordTime等无用的对象

master
richie 6 years ago
parent
commit
b18f350347
  1. 1
      designer-base/src/main/java/com/fr/design/mainframe/loghandler/DesignerLogAppender.java
  2. 84
      designer-base/src/main/java/com/fr/design/mainframe/loghandler/DesignerLogHandler.java
  3. 46
      designer-base/src/main/java/com/fr/design/mainframe/loghandler/DesignerLogImpl.java
  4. 23
      designer-realize/src/main/java/com/fr/design/mainframe/socketio/DesignerSocketIO.java
  5. 5
      designer-realize/src/main/java/com/fr/start/module/DesignerActivator.java

1
designer-base/src/main/java/com/fr/design/mainframe/loghandler/DesignerLogAppender.java

@ -1,7 +1,6 @@
package com.fr.design.mainframe.loghandler; package com.fr.design.mainframe.loghandler;
import com.fr.general.FRLogLevel;
import com.fr.third.apache.log4j.AppenderSkeleton; import com.fr.third.apache.log4j.AppenderSkeleton;
import com.fr.third.apache.log4j.Level; import com.fr.third.apache.log4j.Level;
import com.fr.third.apache.log4j.spi.LoggingEvent; import com.fr.third.apache.log4j.spi.LoggingEvent;

84
designer-base/src/main/java/com/fr/design/mainframe/loghandler/DesignerLogHandler.java

@ -1,17 +1,16 @@
package com.fr.design.mainframe.loghandler; package com.fr.design.mainframe.loghandler;
import com.fr.base.BaseUtils; import com.fr.base.BaseUtils;
import com.fr.base.FRContext;
import com.fr.design.gui.icontainer.UIScrollPane; import com.fr.design.gui.icontainer.UIScrollPane;
import com.fr.design.gui.imenu.UIMenuItem; import com.fr.design.gui.imenu.UIMenuItem;
import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.general.FRLogLevel;
import com.fr.general.Inter; import com.fr.general.Inter;
import com.fr.general.LogRecordTime;
import com.fr.general.log.Log4jConfig; import com.fr.general.log.Log4jConfig;
import com.fr.stable.xml.LogRecordTimeProvider; import com.fr.log.FineLoggerFactory;
import com.fr.third.apache.log4j.Level; import com.fr.third.apache.log4j.Level;
import com.fr.third.apache.log4j.spi.LoggingEvent;
import com.fr.third.apache.log4j.spi.ThrowableInformation;
import javax.swing.*; import javax.swing.*;
import javax.swing.text.BadLocationException; import javax.swing.text.BadLocationException;
@ -29,11 +28,13 @@ import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.logging.LogRecord;
import static com.fr.design.gui.syntax.ui.rtextarea.RTADefaultInputMap.DEFAULT_MODIFIER; import static com.fr.design.gui.syntax.ui.rtextarea.RTADefaultInputMap.DEFAULT_MODIFIER;
public class DesignerLogHandler { public class DesignerLogHandler {
private static final SimpleDateFormat LOG_SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
protected static final int INFO_INT = Level.INFO.toInt(); protected static final int INFO_INT = Level.INFO.toInt();
protected static final int ERROR_INT = Level.ERROR.toInt(); protected static final int ERROR_INT = Level.ERROR.toInt();
protected static final int WARN_INT = Level.WARN.toInt(); protected static final int WARN_INT = Level.WARN.toInt();
@ -67,7 +68,6 @@ public class DesignerLogHandler {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
logHandlerArea.jTextArea.setText(""); logHandlerArea.jTextArea.setText("");
caption.clearMessage(); caption.clearMessage();
DesignerLogImpl.getInstance().clear();
} }
}); });
caption.addSelectedListener(new ActionListener() { caption.addSelectedListener(new ActionListener() {
@ -84,10 +84,6 @@ public class DesignerLogHandler {
public void itemStateChanged(ItemEvent e) { public void itemStateChanged(ItemEvent e) {
logHandlerArea.jTextArea.setText(""); logHandlerArea.jTextArea.setText("");
caption.clearMessage(); caption.clearMessage();
LogRecordTimeProvider[] recorders = DesignerLogImpl.getInstance().getRecorders();
for (LogRecordTimeProvider logRecordTime : recorders) {
logHandlerArea.printStackTrace(logRecordTime);
}
} }
}; };
showInfo = new JCheckBoxMenuItem(Inter.getLocText(new String[]{"Display", "Normal", "Info"}), true); showInfo = new JCheckBoxMenuItem(Inter.getLocText(new String[]{"Display", "Normal", "Info"}), true);
@ -101,7 +97,7 @@ public class DesignerLogHandler {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
JPopupMenu jPopupMenu = new JPopupMenu(); JPopupMenu jPopupMenu = new JPopupMenu();
int logLevelInt = Log4jConfig.getInstance().getRootLevel().toInt(); int logLevelInt = Log4jConfig.getInstance().getRootLevel().toInt();
if (logLevelInt <= INFO_INT) { if (logLevelInt <= INFO_INT) {
jPopupMenu.add(showInfo); jPopupMenu.add(showInfo);
@ -193,55 +189,52 @@ public class DesignerLogHandler {
public void actionPerformed(ActionEvent evt) { public void actionPerformed(ActionEvent evt) {
resultPane.setText(""); resultPane.setText("");
caption.clearMessage(); caption.clearMessage();
DesignerLogImpl.getInstance().clear();
} }
}); });
return resultPane; return resultPane;
} }
public void printStackTrace(LogRecordTimeProvider logRecordTime) { public void printStackTrace(LoggingEvent event) {
LogRecord logRecord = logRecordTime.getLogRecord(); int intLevel = event.getLevel().toInt();
Date date = logRecordTime.getDate(); Date date = new Date(event.getTimeStamp());
int logLevelvalue = logRecord.getLevel().intValue(); ThrowableInformation information = event.getThrowableInformation();
if (logLevelvalue == INFO_INT && showInfo.isSelected()) { if (intLevel == INFO_INT && showInfo.isSelected()) {
printMessage(logRecord.getMessage(), logLevelvalue, date, logRecord.getThrown()); printMessage(event.getRenderedMessage(), intLevel, date, information == null ? null : information.getThrowable());
} else if (logLevelvalue == ERROR_INT && showError.isSelected()) { } else if (intLevel == ERROR_INT && showError.isSelected()) {
printMessage(logRecord.getMessage(), logLevelvalue, date, logRecord.getThrown()); printMessage(event.getRenderedMessage(), intLevel, date, information == null ? null : information.getThrowable());
} else if (logLevelvalue == WARN_INT && showServer.isSelected()) { } else if (intLevel == WARN_INT && showServer.isSelected()) {
printMessage(logRecord.getMessage(), logLevelvalue, date, logRecord.getThrown()); printMessage(event.getRenderedMessage(), intLevel, date, information == null ? null : information.getThrowable());
} }
} }
public void printStackTrace(String message, Level level, Date date) { public void printStackTrace(String message, Level level, Date date) {
int logLevelvalue = level.toInt(); int intLevel = level.toInt();
if (logLevelvalue == INFO_INT && showInfo.isSelected()) { if (intLevel == INFO_INT && showInfo.isSelected()) {
printMessage(message, logLevelvalue, date); printMessage(message, intLevel, date);
} else if (logLevelvalue == ERROR_INT && showError.isSelected()) { } else if (intLevel == ERROR_INT && showError.isSelected()) {
printMessage(message, logLevelvalue, date); printMessage(message, intLevel, date);
} else if (logLevelvalue == WARN_INT && showServer.isSelected()) { } else if (intLevel == WARN_INT && showServer.isSelected()) {
printMessage(message, logLevelvalue, date); printMessage(message, intLevel, date);
} }
} }
private void printMessage(String message, int logLevelvalue, Date date) { private void printMessage(String message, int intLevel, Date date) {
printMessage(message, logLevelvalue, date, null); printMessage(message, intLevel, date, null);
} }
private void printMessage(String messange, int logLevelvalue, Date date, Throwable e) { private void printMessage(String msg, int intLevel, Date date, Throwable e) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); this.log(LOG_SIMPLE_DATE_FORMAT.format(date) + "\n", 0);
this.log(simpleDateFormat.format(date) + "\n", 0); String message = appendLocaleMark(msg, intLevel);
String message = swithInter(messange, logLevelvalue); this.log(message, intLevel);
this.log(message, logLevelvalue); setMessage(message, intLevel);
setMessage(message, logLevelvalue);
if (e == null) { if (e == null) {
return; return;
} }
StackTraceElement[] stacktraceelement = e.getStackTrace(); StackTraceElement[] traceElements = e.getStackTrace();
for (int i = 0; i < stacktraceelement.length; i++) { for (int i = 0; i < traceElements.length; i++) {
this.log("\t" + "at " + stacktraceelement[i].toString() + "\n", 0); this.log("\t" + "at " + traceElements[i].toString() + "\n", 0);
} }
} }
@ -264,11 +257,11 @@ public class DesignerLogHandler {
try { try {
doc.insertString(doc.getLength(), str, attrSet); doc.insertString(doc.getLength(), str, attrSet);
} catch (BadLocationException e) { } catch (BadLocationException e) {
FRContext.getLogger().error(e.getMessage()); FineLoggerFactory.getLogger().error(e.getMessage());
} }
} }
private String swithInter(String str, int style) { private String appendLocaleMark(String str, int style) {
if (style == ERROR_INT) { if (style == ERROR_INT) {
str = Inter.getLocText("FR-Designer_Alert") + ":" + str + "\n"; str = Inter.getLocText("FR-Designer_Alert") + ":" + str + "\n";
} else if (style == WARN_INT) { } else if (style == WARN_INT) {
@ -318,14 +311,13 @@ public class DesignerLogHandler {
} else if (ComparatorUtils.equals(evt.getActionCommand(), LogHandlerArea.this.clear.getText())) { } else if (ComparatorUtils.equals(evt.getActionCommand(), LogHandlerArea.this.clear.getText())) {
LogHandlerArea.this.jTextArea.setText(""); LogHandlerArea.this.jTextArea.setText("");
caption.clearMessage(); caption.clearMessage();
DesignerLogImpl.getInstance().clear();
} }
} }
}; };
} }
public void printRemoteLog(LogRecordTime logRecordTime) { public void printLoggingEvent(LoggingEvent event) {
logHandlerArea.printStackTrace(logRecordTime); logHandlerArea.printStackTrace(event);
} }
} }

46
designer-base/src/main/java/com/fr/design/mainframe/loghandler/DesignerLogImpl.java

@ -1,46 +0,0 @@
package com.fr.design.mainframe.loghandler;
import com.fr.stable.fun.impl.AbstractLogProvider;
import com.fr.stable.xml.LogRecordTimeProvider;
import java.util.ArrayList;
import java.util.List;
/**
* Created by Administrator on 2016/1/11 0011.
*/
public class DesignerLogImpl extends AbstractLogProvider{
private static DesignerLogImpl instance = new DesignerLogImpl();
public static DesignerLogImpl getInstance(){
return instance;
}
private DesignerLogImpl(){
}
private List<LogRecordTimeProvider> records = new ArrayList<LogRecordTimeProvider>();
/**
* 清除内存中的日志记录
*/
public void clear(){
records.clear();
}
/**
* 获取所有日志信息
*
* @return 日志信息
*/
public LogRecordTimeProvider[] getRecorders(){
return records.toArray(new LogRecordTimeProvider[records.size()]);
}
@Override
public void record(LogRecordTimeProvider logRecordTime) {
records.add(logRecordTime);
}
}

23
designer-realize/src/main/java/com/fr/design/mainframe/socketio/DesignerSocketIO.java

@ -4,24 +4,23 @@ import com.fr.config.RemoteConfigEvent;
import com.fr.decision.webservice.utils.DecisionServiceConstants; import com.fr.decision.webservice.utils.DecisionServiceConstants;
import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.loghandler.DesignerLogHandler; import com.fr.design.mainframe.loghandler.DesignerLogHandler;
import com.fr.workspace.server.socket.SocketInfoOperator;
import com.fr.event.EventDispatcher; import com.fr.event.EventDispatcher;
import com.fr.general.Inter; import com.fr.general.Inter;
import com.fr.general.LogRecordTime;
import com.fr.general.LogUtils;
import com.fr.log.FineLoggerFactory; import com.fr.log.FineLoggerFactory;
import com.fr.serialization.SerializerHelper;
import com.fr.stable.ArrayUtils;
import com.fr.third.apache.log4j.spi.LoggingEvent;
import com.fr.third.guava.base.Optional; import com.fr.third.guava.base.Optional;
import com.fr.workspace.WorkContext; import com.fr.workspace.WorkContext;
import com.fr.workspace.Workspace; import com.fr.workspace.Workspace;
import com.fr.workspace.base.WorkspaceConstants; import com.fr.workspace.base.WorkspaceConstants;
import com.fr.workspace.engine.server.rpc.netty.RemoteCallClient; import com.fr.workspace.engine.server.rpc.netty.RemoteCallClient;
import com.fr.workspace.server.socket.SocketInfoOperator;
import io.socket.client.IO; import io.socket.client.IO;
import io.socket.client.Socket; import io.socket.client.Socket;
import io.socket.emitter.Emitter; import io.socket.emitter.Emitter;
import javax.swing.JOptionPane; import javax.swing.*;
import javax.swing.UIManager;
import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.net.URL; import java.net.URL;
@ -33,13 +32,13 @@ public class DesignerSocketIO {
private static final Emitter.Listener printLog = new Emitter.Listener() { private static final Emitter.Listener printLog = new Emitter.Listener() {
@Override @Override
public void call(Object... objects) { public void call(Object... objects) {
try { if (ArrayUtils.isNotEmpty(objects)) {
LogRecordTime[] logRecordTimes = LogUtils.readXMLLogRecords(new ByteArrayInputStream((byte[]) objects[0])); try {
for (LogRecordTime logRecordTime : logRecordTimes) { LoggingEvent event = SerializerHelper.deserialize((byte[]) objects[0]);
DesignerLogHandler.getInstance().printRemoteLog(logRecordTime); DesignerLogHandler.getInstance().printLoggingEvent(event);
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
} }
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
} }
} }
}; };

5
designer-realize/src/main/java/com/fr/start/module/DesignerActivator.java

@ -48,7 +48,6 @@ import com.fr.design.mainframe.form.FormECDesignerProvider;
import com.fr.design.mainframe.form.FormElementCaseDesigner; import com.fr.design.mainframe.form.FormElementCaseDesigner;
import com.fr.design.mainframe.form.FormReportComponentComposite; import com.fr.design.mainframe.form.FormReportComponentComposite;
import com.fr.design.mainframe.loghandler.DesignerLogAppender; import com.fr.design.mainframe.loghandler.DesignerLogAppender;
import com.fr.design.mainframe.loghandler.DesignerLogImpl;
import com.fr.design.mainframe.loghandler.LogMessageBar; import com.fr.design.mainframe.loghandler.LogMessageBar;
import com.fr.design.mainframe.socketio.DesignerSocketIO; import com.fr.design.mainframe.socketio.DesignerSocketIO;
import com.fr.design.module.DesignModuleFactory; import com.fr.design.module.DesignModuleFactory;
@ -91,7 +90,6 @@ import com.fr.report.cell.painter.CellImagePainter;
import com.fr.stable.ArrayUtils; import com.fr.stable.ArrayUtils;
import com.fr.stable.ParameterProvider; import com.fr.stable.ParameterProvider;
import com.fr.stable.bridge.StableFactory; import com.fr.stable.bridge.StableFactory;
import com.fr.stable.fun.LogProvider;
import com.fr.stable.plugin.ExtraDesignClassManagerProvider; import com.fr.stable.plugin.ExtraDesignClassManagerProvider;
import com.fr.stable.script.CalculatorProviderContext; import com.fr.stable.script.CalculatorProviderContext;
import com.fr.stable.script.ValueConverter; import com.fr.stable.script.ValueConverter;
@ -100,7 +98,7 @@ import com.fr.stable.xml.ObjectXMLWriterFinder;
import com.fr.start.BBSGuestPaneProvider; import com.fr.start.BBSGuestPaneProvider;
import com.fr.xml.ReportXMLUtils; import com.fr.xml.ReportXMLUtils;
import java.awt.Image; import java.awt.*;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -165,7 +163,6 @@ public class DesignerActivator extends Activator implements Prepare {
InformationCollector.getInstance().collectStartTime(); InformationCollector.getInstance().collectStartTime();
ExtraDesignClassManager.getInstance().getFeedback().didFeedback(); ExtraDesignClassManager.getInstance().getFeedback().didFeedback();
StableFactory.registerMarkedObject(LogProvider.MARK_STRING, DesignerLogImpl.getInstance());
} }
private static void preLoadPane() { private static void preLoadPane() {

Loading…
Cancel
Save