Browse Source

REPORT-10847 【10.0冒烟】日志级别设置为debug,日志中只查看得到info信息

bug提错了  回退一下
research/10.0
ju 6 years ago
parent
commit
c1c0c303b5
  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.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;
@ -32,57 +41,74 @@ import java.util.Date;
import static com.fr.design.gui.syntax.ui.rtextarea.RTADefaultInputMap.DEFAULT_MODIFIER;
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"));
caption.addClearListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
logHandlerArea.jTextArea.setText("");
caption.clearMessage();
}
});
caption.addSelectedListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
logHandlerArea.jTextArea.requestFocus();
logHandlerArea.jTextArea.selectAll();
}
});
ItemListener itemlistener = new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
logHandlerArea.jTextArea.setText("");
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.addItemListener(itemlistener);
caption.addSetListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JPopupMenu jPopupMenu = new JPopupMenu();
int logLevelInt = Log4jConfig.getInstance().getRootLevel().toInt();
if (logLevelInt <= INFO_INT) {
jPopupMenu.add(showInfo);
@ -116,61 +143,72 @@ 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);
this.add(js, BorderLayout.CENTER);
this.setPreferredSize(new Dimension(super.getPreferredSize().width, 150));
jTextArea.setEditable(false);
jTextArea.setBackground(Color.WHITE);
popup = new JPopupMenu();
selectAll = new UIMenuItem(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Select_All"));
selectAll.addActionListener(popupListener);
selectAll.setIcon(BaseUtils.readIcon("/com/fr/design/images/log/selectedall.png"));
popup.add(selectAll);
copy = new UIMenuItem(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Copy"));
copy.addActionListener(popupListener);
copy.setIcon(BaseUtils.readIcon("/com/fr/design/images/m_edit/copy.png"));
popup.add(copy);
clear = new UIMenuItem(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Clear_All"));
clear.addActionListener(popupListener);
clear.setIcon(BaseUtils.readIcon("/com/fr/design/images/log/clear.png"));
popup.add(clear);
selectAll.setAccelerator(KeyStroke.getKeyStroke('A', DEFAULT_MODIFIER));
copy.setAccelerator(KeyStroke.getKeyStroke('C', DEFAULT_MODIFIER));
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();
@ -178,8 +216,9 @@ 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,15 +226,18 @@ 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();
}
});
return resultPane;
}
public void printStackTrace(LoggingEvent event) {
int intLevel = event.getLevel().toInt();
Date date = new Date(event.getTimeStamp());
ThrowableInformation information = event.getThrowableInformation();
@ -207,27 +249,27 @@ public class DesignerLogHandler {
printMessage(event.getRenderedMessage(), intLevel, date, information == null ? null : information.getThrowable());
}
}
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);
@ -235,14 +277,15 @@ public class DesignerLogHandler {
if (e == null) {
return;
}
StackTraceElement[] traceElements = e.getStackTrace();
for (int i = 0; i < traceElements.length; i++) {
this.log("\t" + "at " + traceElements[i].toString() + "\n", 0);
}
}
private void log(String str, int style) {
SimpleAttributeSet attrSet = new SimpleAttributeSet();
if (style == ERROR_INT) {
StyleConstants.setForeground(attrSet, new Color(247, 148, 29));
@ -264,8 +307,9 @@ public class DesignerLogHandler {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
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) {
@ -275,8 +319,9 @@ public class DesignerLogHandler {
}
return str;
}
private void setMessage(String message, int level) {
LogMessageBar.getInstance().setMessage(message);
if (level == DesignerLogHandler.INFO_INT && showInfo.isSelected()) {
caption.infoAdd();
@ -286,28 +331,31 @@ public class DesignerLogHandler {
caption.serverAdd();
}
}
private void checkEnabled() {
this.selectAll.setEnabled(true);
this.copy.setEnabled(true);
this.clear.setEnabled(true);
if (ComparatorUtils.equals(this.jTextArea.getText(), "")) {
this.selectAll.setEnabled(false);
this.clear.setEnabled(false);
}
if (ComparatorUtils.equals(this.jTextArea.getSelectionStart(), this.jTextArea.getSelectionEnd())) {
this.copy.setEnabled(false);
}
if (this.jTextArea.getSelectionStart() == 0 && ComparatorUtils.equals(this.jTextArea.getSelectionEnd(), this.jTextArea.getText().length())) {
this.selectAll.setEnabled(false);
}
}
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())) {
@ -318,10 +366,11 @@ public class DesignerLogHandler {
}
}
};
}
public void printLoggingEvent(LoggingEvent event) {
logHandlerArea.printStackTrace(event);
}
}

Loading…
Cancel
Save