This is an automated email from the ASF dual-hosted git repository.
jiangtian pushed a commit to branch log_tool
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git
The following commit(s) were added to refs/heads/log_tool by this push:
new 8c018f5 support selecting multiple log files
8c018f5 is described below
commit 8c018f5ac53f6797b2bb3b4ce94be76ec7d15d46
Author: jt <[email protected]>
AuthorDate: Tue Sep 3 17:05:17 2019 +0800
support selecting multiple log files
---
.../iotdb/db/tools/logvisual/LogVisualizer.java | 21 ++++++++++++--
.../iotdb/db/tools/logvisual/PatternLogParser.java | 33 +++++++++++++++-------
.../db/tools/logvisual/gui/FileSelectionBox.java | 5 +++-
.../iotdb/db/tools/logvisual/gui/MainPanel.java | 5 ++--
4 files changed, 49 insertions(+), 15 deletions(-)
diff --git
a/server/src/main/java/org/apache/iotdb/db/tools/logvisual/LogVisualizer.java
b/server/src/main/java/org/apache/iotdb/db/tools/logvisual/LogVisualizer.java
index 6a1c7eb..2fbe96e 100644
---
a/server/src/main/java/org/apache/iotdb/db/tools/logvisual/LogVisualizer.java
+++
b/server/src/main/java/org/apache/iotdb/db/tools/logvisual/LogVisualizer.java
@@ -141,13 +141,30 @@ public class LogVisualizer {
// close the previous
close();
String propertyFilePath = parserPropertyFile.getPath();
- String logFilePath = logFile.getPath();
+ List<String> logFilePaths = new ArrayList<>();
+ getLogFilePaths(logFile, logFilePaths);
Properties properties = new Properties();
try (FileInputStream inputStream = new FileInputStream(propertyFilePath);
BufferedInputStream bufferedInputStream = new
BufferedInputStream(inputStream)) {
properties.load(bufferedInputStream);
}
- logParser = new PatternLogParser(properties, logFilePath);
+ logParser = new PatternLogParser(properties, logFilePaths.toArray(new
String[0]));
+ }
+
+ private void getLogFilePaths(File currLogFile, List<String> logFilePaths) {
+ if (!currLogFile.exists()) {
+ return;
+ }
+ if (currLogFile.isFile()) {
+ logFilePaths.add(currLogFile.getPath());
+ } else {
+ File[] subFiles = currLogFile.listFiles();
+ if (subFiles != null) {
+ for (File subFile : subFiles) {
+ getLogFilePaths(subFile, logFilePaths);
+ }
+ }
+ }
}
public void close() throws IOException {
diff --git
a/server/src/main/java/org/apache/iotdb/db/tools/logvisual/PatternLogParser.java
b/server/src/main/java/org/apache/iotdb/db/tools/logvisual/PatternLogParser.java
index 3d299f1..4ad0740 100644
---
a/server/src/main/java/org/apache/iotdb/db/tools/logvisual/PatternLogParser.java
+++
b/server/src/main/java/org/apache/iotdb/db/tools/logvisual/PatternLogParser.java
@@ -46,11 +46,12 @@ public class PatternLogParser implements LogParser{
private int codeLocationIndex;
private int contentIndex;
- private String logFilePath;
+ private int logFileIdx;
+ private String[] logFilePaths;
private BufferedReader reader;
private DateFormat dateFormat;
- PatternLogParser(Properties properties, String logFilePath) {
+ PatternLogParser(Properties properties, String[] logFilePaths) {
this.pattern =
Pattern.compile(properties.getProperty(PATTERN.getPropertyName()));
this.dateIndex =
Integer.parseInt(properties.getProperty(DATE_INDEX.getPropertyName()));
this.threadNameIndex =
Integer.parseInt(properties.getProperty(THREAD_NAME_INDEX
@@ -61,14 +62,25 @@ public class PatternLogParser implements LogParser{
.getPropertyName(), String.valueOf(-1)));
this.contentIndex =
Integer.parseInt(properties.getProperty(CONTENT_INDEX.getPropertyName()));
this.dateFormat = new
SimpleDateFormat(properties.getProperty(DATE_PATTERN.getPropertyName()));
- this.logFilePath = logFilePath;
+ this.logFilePaths = logFilePaths;
+ this.logFileIdx = -1;
+ }
+
+ private void nextFile() throws IOException {
+ close();
+ reader = new BufferedReader(new InputStreamReader(new
FileInputStream(logFilePaths[++logFileIdx])));
}
@Override
public LogEntry next() throws IOException {
String line = reader.readLine();
- if (line == null) {
- return null;
+ while (line == null) {
+ if (logFileIdx + 1 < logFilePaths.length) {
+ nextFile();
+ line = reader.readLine();
+ } else {
+ return null;
+ }
}
Matcher matcher = pattern.matcher(line);
@@ -103,15 +115,16 @@ public class PatternLogParser implements LogParser{
@Override
public void close() throws IOException {
- reader.close();
+ if (reader != null) {
+ reader.close();
+ }
}
@Override
public void reset() throws IOException {
- if (reader != null) {
- reader.close();
- }
- reader = new BufferedReader(new InputStreamReader(new
FileInputStream(logFilePath)));
+ close();
+ logFileIdx = 0;
+ reader = new BufferedReader(new InputStreamReader(new
FileInputStream(logFilePaths[0])));
}
enum PatternProperties {
diff --git
a/server/src/main/java/org/apache/iotdb/db/tools/logvisual/gui/FileSelectionBox.java
b/server/src/main/java/org/apache/iotdb/db/tools/logvisual/gui/FileSelectionBox.java
index a63c925..536df78 100644
---
a/server/src/main/java/org/apache/iotdb/db/tools/logvisual/gui/FileSelectionBox.java
+++
b/server/src/main/java/org/apache/iotdb/db/tools/logvisual/gui/FileSelectionBox.java
@@ -41,11 +41,13 @@ class FileSelectionBox extends Box{
private JTextField filePathField;
private JButton selectFileButton;
private FilePathBoxSelectionCallBack callBack;
+ private int selectionMode;
FileSelectionBox(String name, FilePathBoxSelectionCallBack callBack, String
- defaultFilePath) {
+ defaultFilePath, int selectionMode) {
super(BoxLayout.X_AXIS);
this.callBack = callBack;
+ this.selectionMode = selectionMode;
panelName = new JLabel(name);
filePathField = new JTextField("No file is selected");
@@ -82,6 +84,7 @@ class FileSelectionBox extends Box{
private void onSelectFileButtonClick() {
JFileChooser fileChooser = new JFileChooser();
+ fileChooser.setFileSelectionMode(selectionMode);
File currentFile = new File(filePathField.getText());
if (currentFile.exists()) {
if (currentFile.isDirectory()) {
diff --git
a/server/src/main/java/org/apache/iotdb/db/tools/logvisual/gui/MainPanel.java
b/server/src/main/java/org/apache/iotdb/db/tools/logvisual/gui/MainPanel.java
index 352e36b..90d23fe 100644
---
a/server/src/main/java/org/apache/iotdb/db/tools/logvisual/gui/MainPanel.java
+++
b/server/src/main/java/org/apache/iotdb/db/tools/logvisual/gui/MainPanel.java
@@ -21,6 +21,7 @@ package org.apache.iotdb.db.tools.logvisual.gui;
import java.io.File;
import java.util.Properties;
+import javax.swing.JFileChooser;
import javax.swing.JPanel;
import org.apache.iotdb.db.tools.logvisual.LogVisualizer;
import org.apache.iotdb.db.tools.logvisual.conf.PropertyKeys;
@@ -68,13 +69,13 @@ class MainPanel extends JPanel {
setLayout(null);
logFileSelectionBox = new FileSelectionBox("LogFilePath",
this::onLogFileSelected,
- properties.getProperty(PropertyKeys.DEFAULT_LOG_FILE_PATH.getKey()));
+ properties.getProperty(PropertyKeys.DEFAULT_LOG_FILE_PATH.getKey()),
JFileChooser.FILES_AND_DIRECTORIES);
logFileSelectionBox.setLocation(0, 0);
logFileSelectionBox.setSize(380, 40);
parserPropertyBox = new FileSelectionBox("ParserPropertyFilePath",
this::onParserPropertySelected, properties.getProperty(PropertyKeys
- .DEFAULT_PARSER_FILE_PATH.getKey()));
+ .DEFAULT_PARSER_FILE_PATH.getKey()), JFileChooser.FILES_ONLY);
parserPropertyBox.setLocation(0, 45);
parserPropertyBox.setSize(380, 40);