Browse Source

Merge pull request #481 in DESIGN/design from ~JU/design:feature/10.0 to feature/10.0

* commit '63773958701f283d5b8c291227f61319d7bf2cfe':
  REPORT-10847 【10.0冒烟】日志级别设置为debug,日志中只查看得到info信息 bug提错了  回退一下
research/10.0
ju 6 years ago
parent
commit
e09eb931c9
  1. 69
      designer-base/src/main/java/com/fr/design/mainframe/loghandler/DesignerLogHandler.java

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

@ -5,20 +5,29 @@ import com.fr.design.gui.icontainer.UIScrollPane;
import com.fr.design.gui.imenu.UIMenuItem;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.general.ComparatorUtils;
import com.fr.general.log.Log4jConfig;
import com.fr.log.FineLoggerFactory;
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.AbstractAction;
import javax.swing.ActionMap;
import javax.swing.InputMap;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JTextPane;
import javax.swing.KeyStroke;
import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultEditorKit;
import javax.swing.text.Document;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import java.awt.*;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
@ -35,31 +44,45 @@ 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 ERROR_INT = Level.ERROR.toInt();
protected static final int WARN_INT = Level.WARN.toInt();
protected static final int DEBUG_INT = Level.DEBUG.toInt();
private static final int INFO_INT = Level.INFO.toInt();
private static final int ERROR_INT = Level.ERROR.toInt();
private static final int WARN_INT = Level.WARN.toInt();
private static final int DEBUG_INT = Level.DEBUG.toInt();
private static final int GAP_X = -150;
private static final int INFO_GAP_Y = -60;
private static final int ERRO_GAP_Y = -40;
private static final int SERVER_GAP_Y = -20;
public static DesignerLogHandler getInstance() {
return HOLDER.singleton;
}
private static class HOLDER {
private static DesignerLogHandler singleton = new DesignerLogHandler();
}
// 所有的面板
private LogHandlerBar caption;
private JCheckBoxMenuItem showInfo;
private JCheckBoxMenuItem showError;
private JCheckBoxMenuItem showServer;
private LogHandlerArea logHandlerArea;
public DesignerLogHandler() {
logHandlerArea = new LogHandlerArea();
caption = new LogHandlerBar(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Log"));
@ -67,6 +90,7 @@ public class DesignerLogHandler {
@Override
public void actionPerformed(ActionEvent e) {
logHandlerArea.jTextArea.setText("");
caption.clearMessage();
}
@ -75,6 +99,7 @@ public class DesignerLogHandler {
@Override
public void actionPerformed(ActionEvent e) {
logHandlerArea.jTextArea.requestFocus();
logHandlerArea.jTextArea.selectAll();
}
@ -83,6 +108,7 @@ public class DesignerLogHandler {
@Override
public void itemStateChanged(ItemEvent e) {
logHandlerArea.jTextArea.setText("");
caption.clearMessage();
}
@ -97,6 +123,7 @@ public class DesignerLogHandler {
@Override
public void actionPerformed(ActionEvent e) {
JPopupMenu jPopupMenu = new JPopupMenu();
int logLevelInt = Log4jConfig.getInstance().getRootLevel().toInt();
@ -118,27 +145,36 @@ public class DesignerLogHandler {
}
public JComponent getLogHandlerArea() {
return logHandlerArea;
}
public JComponent getCaption() {
return caption;
}
public void printRemoteLog(String message, Level level, Date date) {
logHandlerArea.printStackTrace(message, level, date);
}
private class LogHandlerArea extends JPanel {
private static final long serialVersionUID = 8215630927304621660L;
private JTextPane jTextArea;
private JPopupMenu popup;
private UIMenuItem selectAll;
private UIMenuItem copy;
private UIMenuItem clear;
private LogHandlerArea() {
jTextArea = initLogJTextArea();
this.setLayout(FRGUIPaneFactory.createBorderLayout());
UIScrollPane js = new UIScrollPane(jTextArea);
@ -169,8 +205,10 @@ public class DesignerLogHandler {
clear.setAccelerator(KeyStroke.getKeyStroke('L', DEFAULT_MODIFIER));
jTextArea.addMouseListener(new MouseAdapter() {
// check for right click
public void mousePressed(MouseEvent event) {
if (event.getButton() == MouseEvent.BUTTON3) {
popup.show(jTextArea, event.getX(), event.getY());
checkEnabled();
@ -180,6 +218,7 @@ public class DesignerLogHandler {
}
private JTextPane initLogJTextArea() {
final JTextPane resultPane = new JTextPane();
InputMap inputMap = resultPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_C, DEFAULT_MODIFIER), DefaultEditorKit.copyAction);
@ -187,7 +226,9 @@ public class DesignerLogHandler {
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_L, DEFAULT_MODIFIER), "clear");
ActionMap actionMap = resultPane.getActionMap();
actionMap.put("clear", new AbstractAction() {
public void actionPerformed(ActionEvent evt) {
resultPane.setText("");
caption.clearMessage();
}
@ -196,6 +237,7 @@ public class DesignerLogHandler {
}
public void printStackTrace(LoggingEvent event) {
int intLevel = event.getLevel().toInt();
Date date = new Date(event.getTimeStamp());
ThrowableInformation information = event.getThrowableInformation();
@ -209,25 +251,25 @@ public class DesignerLogHandler {
}
public void printStackTrace(String message, Level level, Date date) {
int intLevel = level.toInt();
int logLevel = Log4jConfig.getInstance().getRootLevel().toInt();
if (intLevel == INFO_INT && showInfo.isSelected()) {
printMessage(message, intLevel, date);
} else if (intLevel == ERROR_INT && showError.isSelected()) {
printMessage(message, intLevel, date);
} else if (intLevel == WARN_INT && showServer.isSelected()) {
printMessage(message, intLevel, date);
} else if (intLevel == DEBUG_INT && logLevel == DEBUG_INT){
printMessage(message, intLevel, date);
}
}
private void printMessage(String message, int intLevel, Date date) {
printMessage(message, intLevel, date, null);
}
private void printMessage(String msg, int intLevel, Date date, Throwable e) {
this.log(LOG_SIMPLE_DATE_FORMAT.format(date) + "\n", 0);
String message = appendLocaleMark(msg, intLevel);
this.log(message, intLevel);
@ -243,6 +285,7 @@ public class DesignerLogHandler {
}
private void log(String str, int style) {
SimpleAttributeSet attrSet = new SimpleAttributeSet();
if (style == ERROR_INT) {
StyleConstants.setForeground(attrSet, new Color(247, 148, 29));
@ -266,6 +309,7 @@ public class DesignerLogHandler {
}
private String appendLocaleMark(String str, int style) {
if (style == ERROR_INT) {
str = com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Alert") + ":" + str + "\n";
} else if (style == WARN_INT) {
@ -277,6 +321,7 @@ public class DesignerLogHandler {
}
private void setMessage(String message, int level) {
LogMessageBar.getInstance().setMessage(message);
if (level == DesignerLogHandler.INFO_INT && showInfo.isSelected()) {
caption.infoAdd();
@ -288,6 +333,7 @@ public class DesignerLogHandler {
}
private void checkEnabled() {
this.selectAll.setEnabled(true);
this.copy.setEnabled(true);
this.clear.setEnabled(true);
@ -307,7 +353,9 @@ public class DesignerLogHandler {
}
ActionListener popupListener = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (ComparatorUtils.equals(evt.getActionCommand(), LogHandlerArea.this.selectAll.getText())) {
LogHandlerArea.this.jTextArea.selectAll();
} else if (ComparatorUtils.equals(evt.getActionCommand(), LogHandlerArea.this.copy.getText())) {
@ -322,6 +370,7 @@ public class DesignerLogHandler {
}
public void printLoggingEvent(LoggingEvent event) {
logHandlerArea.printStackTrace(event);
}
}

Loading…
Cancel
Save