Browse Source

Merge pull request #999 in BA/design from ~NEIL/design:9.0 to 9.0

* commit 'e2790a4cc8ffb16c10998e2b0343c88c4d70ef19':
  utf8
  REPORT-1013 用log4j记录日志.
master
superman 7 years ago
parent
commit
21cf2b783d
  1. 2
      designer_base/src/com/fr/design/DesignerEnvManager.java
  2. 60
      designer_base/src/com/fr/design/mainframe/loghandler/DesignerLogAppendThread.java
  3. 24
      designer_base/src/com/fr/design/mainframe/loghandler/DesignerLogHandler.java
  4. 6
      designer_base/src/com/fr/design/module/DesignModule.java

2
designer_base/src/com/fr/design/DesignerEnvManager.java

@ -28,7 +28,7 @@ import java.util.List;
import java.util.Map.Entry;
import java.util.logging.FileHandler;
import java.util.logging.Handler;
import java.util.logging.Level;
import org.apache.log4j.Level;
/**
* The manager of Designer GUI.

60
designer_base/src/com/fr/design/mainframe/loghandler/DesignerLogAppendThread.java

@ -0,0 +1,60 @@
package com.fr.design.mainframe.loghandler;
import com.fr.general.LogRecordTime;
import com.fr.stable.StringUtils;
import org.apache.log4j.Appender;
import org.apache.log4j.Logger;
import org.apache.log4j.WriterAppender;
import java.io.PipedReader;
import java.io.PipedWriter;
import java.io.Writer;
import java.util.Date;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.LogRecord;
/**
* Created by Administrator on 2017/6/2/0002.
*/
public class DesignerLogAppendThread extends Thread{
PipedReader reader;
public DesignerLogAppendThread() {
Logger root = Logger.getRootLogger();
// 获取子记录器的输出源
Appender appender = root.getAppender("design");
// 定义一个未连接的输入流管道
reader = new PipedReader();
// 定义一个已连接的输出流管理,并连接到reader
Writer writer = null;
try {
writer = new PipedWriter(reader);
// 设置 appender 输出流
((WriterAppender) appender).setWriter(writer);
} catch (Throwable e) {
}
}
public void run() {
// 不间断地扫描输入流
Scanner scanner = new Scanner(reader);
// 将扫描到的字符流打印在屏目
while (scanner.hasNext()) {
try {
Thread.sleep(100);
String log = scanner.nextLine();
if (StringUtils.isEmpty(log)) {
return;
}
LogRecordTime logRecordTime = new LogRecordTime(new Date(),new LogRecord(Level.INFO, log));
DesignerLogHandler.getInstance().printRemoteLog(logRecordTime);
} catch (Throwable e) {
}
}
}
}

24
designer_base/src/com/fr/design/mainframe/loghandler/DesignerLogHandler.java

@ -18,15 +18,14 @@ import java.awt.*;
import java.awt.event.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Handler;
import java.util.logging.LogRecord;
import static com.fr.design.gui.syntax.ui.rtextarea.RTADefaultInputMap.DEFAULT_MODIFIER;
public class DesignerLogHandler {
protected static final int INFO_INT = FRLogLevel.INFO.intValue();
protected static final int ERRO_INT = FRLogLevel.ERROR.intValue();
protected static final int SERVER_INT = FRLogLevel.SEVERE.intValue();
protected static final int INFO_INT = FRLogLevel.INFO.toInt();
protected static final int ERRO_INT = FRLogLevel.ERROR.toInt();
protected static final int SERVER_INT = FRLogLevel.SEVERE.toInt();
private static final int GAP_X = -150;
private static final int INFO_GAP_Y = -60;
private static final int ERRO_GAP_Y = -40;
@ -91,7 +90,7 @@ public class DesignerLogHandler {
@Override
public void actionPerformed(ActionEvent e) {
JPopupMenu showsetPopup = new JPopupMenu();
int logLevelvalue = DesignerEnvManager.getEnvManager().getLogLevel().intValue();
int logLevelvalue = DesignerEnvManager.getEnvManager().getLogLevel().toInt();
if (logLevelvalue <= INFO_INT) {
showsetPopup.add(showInfo);
showsetPopup.add(showError);
@ -169,21 +168,6 @@ public class DesignerLogHandler {
}
}
});
// 写到日志面板上面的Log和日志工具栏
FRContext.getLogger().addLogHandler(new Handler() {
public void publish(LogRecord logRecord) {
Date date = new Date();
LogRecordTime logRecordTime = new LogRecordTime(date, logRecord);
printStackTrace(logRecordTime);
}
public void flush() {
}
public void close() {
}
});
}
private JTextPane initLogJTextArea() {

6
designer_base/src/com/fr/design/module/DesignModule.java

@ -12,11 +12,11 @@ import com.fr.design.javascript.JavaScriptImplPane;
import com.fr.design.javascript.ParameterJavaScriptPane;
import com.fr.design.mainframe.App;
import com.fr.design.mainframe.DesignerFrame;
import com.fr.design.mainframe.loghandler.DesignerLogAppendThread;
import com.fr.general.Inter;
import com.fr.general.ModuleContext;
import com.fr.js.*;
import com.fr.module.TopModule;
import com.fr.stable.ArrayUtils;
import com.fr.stable.bridge.StableFactory;
import com.fr.stable.plugin.ExtraDesignClassManagerProvider;
@ -45,6 +45,10 @@ public abstract class DesignModule extends TopModule {
ActionFactory.registerCellInsertActionClass(actionsForInsertCellElement());
ActionFactory.registerFloatInsertActionClass(actionsForInsertFloatElement());
DesignModuleFactory.registerCreators4Hyperlink(hyperlinkTypes());
// 将log4j日志输出到设计器日志面板的线程.
DesignerLogAppendThread logTread = new DesignerLogAppendThread();
logTread.start();
}
public boolean isStarted() {

Loading…
Cancel
Save