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. 151
      designer-base/src/main/java/com/fr/design/mainframe/loghandler/DesignerLogHandler.java

151
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.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.log.Log4jConfig; import com.fr.general.log.Log4jConfig;
import com.fr.log.FineLoggerFactory; 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.LoggingEvent;
import com.fr.third.apache.log4j.spi.ThrowableInformation; 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.BadLocationException;
import javax.swing.text.DefaultEditorKit; import javax.swing.text.DefaultEditorKit;
import javax.swing.text.Document; import javax.swing.text.Document;
import javax.swing.text.SimpleAttributeSet; import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants; 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.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.ItemEvent; import java.awt.event.ItemEvent;
@ -32,57 +41,74 @@ import java.util.Date;
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"); 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(); private 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(); private static final int ERROR_INT = Level.ERROR.toInt();
protected static final int DEBUG_INT = Level.DEBUG.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 GAP_X = -150;
private static final int INFO_GAP_Y = -60; private static final int INFO_GAP_Y = -60;
private static final int ERRO_GAP_Y = -40; private static final int ERRO_GAP_Y = -40;
private static final int SERVER_GAP_Y = -20; private static final int SERVER_GAP_Y = -20;
public static DesignerLogHandler getInstance() { public static DesignerLogHandler getInstance() {
return HOLDER.singleton; return HOLDER.singleton;
} }
private static class HOLDER { private static class HOLDER {
private static DesignerLogHandler singleton = new DesignerLogHandler(); private static DesignerLogHandler singleton = new DesignerLogHandler();
} }
// 所有的面板 // 所有的面板
private LogHandlerBar caption; private LogHandlerBar caption;
private JCheckBoxMenuItem showInfo; private JCheckBoxMenuItem showInfo;
private JCheckBoxMenuItem showError; private JCheckBoxMenuItem showError;
private JCheckBoxMenuItem showServer; private JCheckBoxMenuItem showServer;
private LogHandlerArea logHandlerArea; private LogHandlerArea logHandlerArea;
public DesignerLogHandler() { public DesignerLogHandler() {
logHandlerArea = new LogHandlerArea(); logHandlerArea = new LogHandlerArea();
caption = new LogHandlerBar(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Log")); caption = new LogHandlerBar(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Log"));
caption.addClearListener(new ActionListener() { caption.addClearListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
logHandlerArea.jTextArea.setText(""); logHandlerArea.jTextArea.setText("");
caption.clearMessage(); caption.clearMessage();
} }
}); });
caption.addSelectedListener(new ActionListener() { caption.addSelectedListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
logHandlerArea.jTextArea.requestFocus(); logHandlerArea.jTextArea.requestFocus();
logHandlerArea.jTextArea.selectAll(); logHandlerArea.jTextArea.selectAll();
} }
}); });
ItemListener itemlistener = new ItemListener() { ItemListener itemlistener = new ItemListener() {
@Override @Override
public void itemStateChanged(ItemEvent e) { public void itemStateChanged(ItemEvent e) {
logHandlerArea.jTextArea.setText(""); logHandlerArea.jTextArea.setText("");
caption.clearMessage(); caption.clearMessage();
} }
@ -94,11 +120,12 @@ public class DesignerLogHandler {
showServer = new JCheckBoxMenuItem(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Log_Level_Error"), true); showServer = new JCheckBoxMenuItem(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Log_Level_Error"), true);
showServer.addItemListener(itemlistener); showServer.addItemListener(itemlistener);
caption.addSetListener(new ActionListener() { caption.addSetListener(new ActionListener() {
@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);
@ -116,61 +143,72 @@ public class DesignerLogHandler {
} }
}); });
} }
public JComponent getLogHandlerArea() { public JComponent getLogHandlerArea() {
return logHandlerArea; return logHandlerArea;
} }
public JComponent getCaption() { public JComponent getCaption() {
return caption; return caption;
} }
public void printRemoteLog(String message, Level level, Date date) { public void printRemoteLog(String message, Level level, Date date) {
logHandlerArea.printStackTrace(message, level, date); logHandlerArea.printStackTrace(message, level, date);
} }
private class LogHandlerArea extends JPanel { private class LogHandlerArea extends JPanel {
private static final long serialVersionUID = 8215630927304621660L; private static final long serialVersionUID = 8215630927304621660L;
private JTextPane jTextArea; private JTextPane jTextArea;
private JPopupMenu popup; private JPopupMenu popup;
private UIMenuItem selectAll; private UIMenuItem selectAll;
private UIMenuItem copy; private UIMenuItem copy;
private UIMenuItem clear; private UIMenuItem clear;
private LogHandlerArea() { private LogHandlerArea() {
jTextArea = initLogJTextArea(); jTextArea = initLogJTextArea();
this.setLayout(FRGUIPaneFactory.createBorderLayout()); this.setLayout(FRGUIPaneFactory.createBorderLayout());
UIScrollPane js = new UIScrollPane(jTextArea); UIScrollPane js = new UIScrollPane(jTextArea);
this.add(js, BorderLayout.CENTER); this.add(js, BorderLayout.CENTER);
this.setPreferredSize(new Dimension(super.getPreferredSize().width, 150)); this.setPreferredSize(new Dimension(super.getPreferredSize().width, 150));
jTextArea.setEditable(false); jTextArea.setEditable(false);
jTextArea.setBackground(Color.WHITE); jTextArea.setBackground(Color.WHITE);
popup = new JPopupMenu(); popup = new JPopupMenu();
selectAll = new UIMenuItem(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Select_All")); selectAll = new UIMenuItem(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Select_All"));
selectAll.addActionListener(popupListener); selectAll.addActionListener(popupListener);
selectAll.setIcon(BaseUtils.readIcon("/com/fr/design/images/log/selectedall.png")); selectAll.setIcon(BaseUtils.readIcon("/com/fr/design/images/log/selectedall.png"));
popup.add(selectAll); popup.add(selectAll);
copy = new UIMenuItem(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Copy")); copy = new UIMenuItem(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Copy"));
copy.addActionListener(popupListener); copy.addActionListener(popupListener);
copy.setIcon(BaseUtils.readIcon("/com/fr/design/images/m_edit/copy.png")); copy.setIcon(BaseUtils.readIcon("/com/fr/design/images/m_edit/copy.png"));
popup.add(copy); popup.add(copy);
clear = new UIMenuItem(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Clear_All")); clear = new UIMenuItem(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Clear_All"));
clear.addActionListener(popupListener); clear.addActionListener(popupListener);
clear.setIcon(BaseUtils.readIcon("/com/fr/design/images/log/clear.png")); clear.setIcon(BaseUtils.readIcon("/com/fr/design/images/log/clear.png"));
popup.add(clear); popup.add(clear);
selectAll.setAccelerator(KeyStroke.getKeyStroke('A', DEFAULT_MODIFIER)); selectAll.setAccelerator(KeyStroke.getKeyStroke('A', DEFAULT_MODIFIER));
copy.setAccelerator(KeyStroke.getKeyStroke('C', DEFAULT_MODIFIER)); copy.setAccelerator(KeyStroke.getKeyStroke('C', DEFAULT_MODIFIER));
clear.setAccelerator(KeyStroke.getKeyStroke('L', DEFAULT_MODIFIER)); clear.setAccelerator(KeyStroke.getKeyStroke('L', DEFAULT_MODIFIER));
jTextArea.addMouseListener(new MouseAdapter() { jTextArea.addMouseListener(new MouseAdapter() {
// check for right click // check for right click
public void mousePressed(MouseEvent event) { public void mousePressed(MouseEvent event) {
if (event.getButton() == MouseEvent.BUTTON3) { if (event.getButton() == MouseEvent.BUTTON3) {
popup.show(jTextArea, event.getX(), event.getY()); popup.show(jTextArea, event.getX(), event.getY());
checkEnabled(); checkEnabled();
@ -178,8 +216,9 @@ public class DesignerLogHandler {
} }
}); });
} }
private JTextPane initLogJTextArea() { private JTextPane initLogJTextArea() {
final JTextPane resultPane = new JTextPane(); final JTextPane resultPane = new JTextPane();
InputMap inputMap = resultPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); InputMap inputMap = resultPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_C, DEFAULT_MODIFIER), DefaultEditorKit.copyAction); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_C, DEFAULT_MODIFIER), DefaultEditorKit.copyAction);
@ -187,15 +226,18 @@ public class DesignerLogHandler {
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_L, DEFAULT_MODIFIER), "clear"); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_L, DEFAULT_MODIFIER), "clear");
ActionMap actionMap = resultPane.getActionMap(); ActionMap actionMap = resultPane.getActionMap();
actionMap.put("clear", new AbstractAction() { actionMap.put("clear", new AbstractAction() {
public void actionPerformed(ActionEvent evt) { public void actionPerformed(ActionEvent evt) {
resultPane.setText(""); resultPane.setText("");
caption.clearMessage(); caption.clearMessage();
} }
}); });
return resultPane; return resultPane;
} }
public void printStackTrace(LoggingEvent event) { public void printStackTrace(LoggingEvent event) {
int intLevel = event.getLevel().toInt(); int intLevel = event.getLevel().toInt();
Date date = new Date(event.getTimeStamp()); Date date = new Date(event.getTimeStamp());
ThrowableInformation information = event.getThrowableInformation(); ThrowableInformation information = event.getThrowableInformation();
@ -207,27 +249,27 @@ public class DesignerLogHandler {
printMessage(event.getRenderedMessage(), intLevel, date, information == null ? null : information.getThrowable()); 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 intLevel = level.toInt(); int intLevel = level.toInt();
int logLevel = Log4jConfig.getInstance().getRootLevel().toInt();
if (intLevel == INFO_INT && showInfo.isSelected()) { if (intLevel == INFO_INT && showInfo.isSelected()) {
printMessage(message, intLevel, date); printMessage(message, intLevel, date);
} else if (intLevel == ERROR_INT && showError.isSelected()) { } else if (intLevel == ERROR_INT && showError.isSelected()) {
printMessage(message, intLevel, date); printMessage(message, intLevel, date);
} else if (intLevel == WARN_INT && showServer.isSelected()) { } else if (intLevel == WARN_INT && showServer.isSelected()) {
printMessage(message, intLevel, date); 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) { private void printMessage(String message, int intLevel, Date date) {
printMessage(message, intLevel, date, null); printMessage(message, intLevel, date, null);
} }
private void printMessage(String msg, int intLevel, Date date, Throwable e) { private void printMessage(String msg, int intLevel, Date date, Throwable e) {
this.log(LOG_SIMPLE_DATE_FORMAT.format(date) + "\n", 0); this.log(LOG_SIMPLE_DATE_FORMAT.format(date) + "\n", 0);
String message = appendLocaleMark(msg, intLevel); String message = appendLocaleMark(msg, intLevel);
this.log(message, intLevel); this.log(message, intLevel);
@ -235,14 +277,15 @@ public class DesignerLogHandler {
if (e == null) { if (e == null) {
return; return;
} }
StackTraceElement[] traceElements = e.getStackTrace(); StackTraceElement[] traceElements = e.getStackTrace();
for (int i = 0; i < traceElements.length; i++) { for (int i = 0; i < traceElements.length; i++) {
this.log("\t" + "at " + traceElements[i].toString() + "\n", 0); this.log("\t" + "at " + traceElements[i].toString() + "\n", 0);
} }
} }
private void log(String str, int style) { private void log(String str, int style) {
SimpleAttributeSet attrSet = new SimpleAttributeSet(); SimpleAttributeSet attrSet = new SimpleAttributeSet();
if (style == ERROR_INT) { if (style == ERROR_INT) {
StyleConstants.setForeground(attrSet, new Color(247, 148, 29)); StyleConstants.setForeground(attrSet, new Color(247, 148, 29));
@ -264,8 +307,9 @@ public class DesignerLogHandler {
FineLoggerFactory.getLogger().error(e.getMessage(), e); FineLoggerFactory.getLogger().error(e.getMessage(), e);
} }
} }
private String appendLocaleMark(String str, int style) { private String appendLocaleMark(String str, int style) {
if (style == ERROR_INT) { if (style == ERROR_INT) {
str = com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Alert") + ":" + str + "\n"; str = com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Alert") + ":" + str + "\n";
} else if (style == WARN_INT) { } else if (style == WARN_INT) {
@ -275,8 +319,9 @@ public class DesignerLogHandler {
} }
return str; return str;
} }
private void setMessage(String message, int level) { private void setMessage(String message, int level) {
LogMessageBar.getInstance().setMessage(message); LogMessageBar.getInstance().setMessage(message);
if (level == DesignerLogHandler.INFO_INT && showInfo.isSelected()) { if (level == DesignerLogHandler.INFO_INT && showInfo.isSelected()) {
caption.infoAdd(); caption.infoAdd();
@ -286,28 +331,31 @@ public class DesignerLogHandler {
caption.serverAdd(); caption.serverAdd();
} }
} }
private void checkEnabled() { private void checkEnabled() {
this.selectAll.setEnabled(true); this.selectAll.setEnabled(true);
this.copy.setEnabled(true); this.copy.setEnabled(true);
this.clear.setEnabled(true); this.clear.setEnabled(true);
if (ComparatorUtils.equals(this.jTextArea.getText(), "")) { if (ComparatorUtils.equals(this.jTextArea.getText(), "")) {
this.selectAll.setEnabled(false); this.selectAll.setEnabled(false);
this.clear.setEnabled(false); this.clear.setEnabled(false);
} }
if (ComparatorUtils.equals(this.jTextArea.getSelectionStart(), this.jTextArea.getSelectionEnd())) { if (ComparatorUtils.equals(this.jTextArea.getSelectionStart(), this.jTextArea.getSelectionEnd())) {
this.copy.setEnabled(false); this.copy.setEnabled(false);
} }
if (this.jTextArea.getSelectionStart() == 0 && ComparatorUtils.equals(this.jTextArea.getSelectionEnd(), this.jTextArea.getText().length())) { if (this.jTextArea.getSelectionStart() == 0 && ComparatorUtils.equals(this.jTextArea.getSelectionEnd(), this.jTextArea.getText().length())) {
this.selectAll.setEnabled(false); this.selectAll.setEnabled(false);
} }
} }
ActionListener popupListener = new ActionListener() { ActionListener popupListener = new ActionListener() {
public void actionPerformed(ActionEvent evt) { public void actionPerformed(ActionEvent evt) {
if (ComparatorUtils.equals(evt.getActionCommand(), LogHandlerArea.this.selectAll.getText())) { if (ComparatorUtils.equals(evt.getActionCommand(), LogHandlerArea.this.selectAll.getText())) {
LogHandlerArea.this.jTextArea.selectAll(); LogHandlerArea.this.jTextArea.selectAll();
} else if (ComparatorUtils.equals(evt.getActionCommand(), LogHandlerArea.this.copy.getText())) { } else if (ComparatorUtils.equals(evt.getActionCommand(), LogHandlerArea.this.copy.getText())) {
@ -318,10 +366,11 @@ public class DesignerLogHandler {
} }
} }
}; };
} }
public void printLoggingEvent(LoggingEvent event) { public void printLoggingEvent(LoggingEvent event) {
logHandlerArea.printStackTrace(event); logHandlerArea.printStackTrace(event);
} }
} }

Loading…
Cancel
Save