|
|
@ -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); |
|
|
@ -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); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |