Skip to content

Commit

Permalink
Merged LogViewerAction into LogViewerButtonAction. Reworked how viewe…
Browse files Browse the repository at this point in the history
…rs get configured and io names get generated, etc.
  • Loading branch information
creechy committed Sep 14, 2012
1 parent f60c0a9 commit 79a5ef5
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 122 deletions.
24 changes: 13 additions & 11 deletions src/org/fakebelieve/netbeans/plugin/logviewer/FileLogViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ public class FileLogViewer extends LogViewer {
* @param process process whose streams to connect to the output window
* @param ioName name of the output window tab to use
*/
public FileLogViewer(String logConfig, final String ioName) {
super(logConfig, ioName);
public FileLogViewer(String logConfig) {
super(logConfig);

if (logConfig.length() > maxIoName) {
this.ioName = "..." + logConfig.substring(logConfig.length() - maxIoName);
}
}

public static boolean handleConfig(String logConfig) {
Expand All @@ -35,15 +39,13 @@ public static boolean handleConfig(String logConfig) {
@Override
public void configViewer() throws IOException {

File logFile = new File(logConfig);
logStream = new FileInputStream(logFile);
logReader = new BufferedReader(new InputStreamReader(logStream));
lineReader = new LineReader(logReader);
File logFile = new File(logConfig);
logStream = new FileInputStream(logFile);
logReader = new BufferedReader(new InputStreamReader(logStream));
lineReader = new LineReader(logReader);

io.getOut().println("*** -> " + logConfig);
io.getOut().println("***");
io.getOut().println();
log.log(Level.FINE, "Started reader.");
io.getOut().println("* -> " + logConfig);
io.getOut().println();
log.log(Level.FINE, "Started reader.");
}

}
16 changes: 11 additions & 5 deletions src/org/fakebelieve/netbeans/plugin/logviewer/LogViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
*/
public class LogViewer implements Runnable {

protected int maxIoName = 36;
protected static final Logger log = Logger.getLogger(LogViewer.class.getName());
ContextLogSupport logSupport;
protected InputStream logStream = null;
Expand All @@ -50,12 +51,18 @@ public class LogViewer implements Runnable {
* @param process process whose streams to connect to the output window
* @param ioName name of the output window tab to use
*/
public LogViewer(String logConfig, final String ioName) {
this.logConfig = logConfig;
this.ioName = ioName;

public LogViewer() {
logSupport = new ContextLogSupport("/tmp", null);
}

public LogViewer(String logConfig) {
this();

this.logConfig = logConfig;
this.ioName = logConfig;
}

public static boolean handleConfig(String logConfig) {
return false;
}
Expand Down Expand Up @@ -171,8 +178,7 @@ public void stopUpdatingLogViewer() {
logReader.close();
logStream.close();
io.getOut().println();
io.getOut().println("***");
io.getOut().println("*** monitoring ended.");
io.getOut().println("* monitoring ended.");
//io.closeInputOutput();
//io.setOutputVisible(false);
} catch (IOException e) {
Expand Down
82 changes: 0 additions & 82 deletions src/org/fakebelieve/netbeans/plugin/logviewer/LogViewerAction.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.prefs.Preferences;
import org.openide.DialogDescriptor;
Expand All @@ -33,6 +32,7 @@ public class LogViewerButtonAction implements ActionListener {

protected static final Logger log = Logger.getLogger(LogViewer.class.getName());
protected Preferences preferences = NbPreferences.forModule(LogViewer.class);
protected int nameSize = 30;

protected List<String> loadHistory() {
List<String> logHistory = new ArrayList<String>();
Expand Down Expand Up @@ -82,22 +82,29 @@ public void actionPerformed(ActionEvent e) {
System.out.println(myPanel.getLogConfig());
String logConfig = myPanel.getLogConfig();
updateHistory(logHistory, logConfig);

String logName = (logConfig.startsWith("!")) ? logConfig.substring(1).trim() : logConfig.trim();
if (logName.length() > 40) {
logName = logName.substring(0, 20) + "..." + logName.substring(logName.length() - 20);
}
viewLog(logConfig, Integer.parseInt(myPanel.getLookbackConfig()), Integer.parseInt(myPanel.getRefreshConfig()));
}
}

// REMIND: This seems a little backwards, should probably rework it.
Map map = new HashMap();
map.put("viewerAction", new LogViewerAction());
map.put("displayName", logName + " (log)");
map.put("name", logName + " (log)");
map.put("lookback", myPanel.getLookbackConfig());
map.put("refresh", myPanel.getRefreshConfig());
public void viewLog(String logConfig, int lookback, int refresh) {
LogViewer viewer = null;
if (FileLogViewer.handleConfig(logConfig)) {
viewer = new FileLogViewer(logConfig);
} else if (ProcessLogViewer.handleConfig(logConfig)) {
viewer = new ProcessLogViewer(logConfig);
} else if (SshLogViewer.handleConfig(logConfig)) {
viewer = new SshLogViewer(logConfig);
}

if (viewer != null) {
viewer.setLookbackLines(lookback);
viewer.setRefreshInterval(refresh);

LogViewerAction logAction = LogViewerAction.getLogViewerAction(map);
logAction.viewLog(logConfig);
try {
viewer.showLogViewer();
} catch (java.io.IOException e) {
log.log(Level.SEVERE, "Showing log action failed.", e);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ public class ProcessLogViewer extends LogViewer {
* @param process process whose streams to connect to the output window
* @param ioName name of the output window tab to use
*/
public ProcessLogViewer(String logConfig, final String ioName) {
super(logConfig.substring(1), ioName);
public ProcessLogViewer(String logConfig) {
super(logConfig.substring(1));
if (logConfig.length() > maxIoName) {
this.ioName = logConfig.substring(0, maxIoName / 2) + "..." + logConfig.substring(logConfig.length() - maxIoName / 2);
}
}

public static boolean handleConfig(String logConfig) {
Expand Down Expand Up @@ -62,8 +65,7 @@ public void configViewer() throws IOException {
logReader = new BufferedReader(new InputStreamReader(logStream));
lineReader = new LineReader(logReader);

io.getOut().println("*** -> " + logConfig);
io.getOut().println("***");
io.getOut().println("* -> " + logConfig);
io.getOut().println();
log.log(Level.FINE, "Started process.");
}
Expand Down
13 changes: 9 additions & 4 deletions src/org/fakebelieve/netbeans/plugin/logviewer/SshLogViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@
public class SshLogViewer extends ProcessLogViewer {

// ssh://user@host/...

public SshLogViewer(String logConfig, String ioName) {
super(logConfig, ioName);
public SshLogViewer(String logConfig) {
super(logConfig);
if (logConfig.length() > maxIoName) {
int pathStart = logConfig.indexOf("/", 6);
String nameStart = logConfig.substring(0, pathStart + 1);
String logPath = logConfig.substring(logConfig.length() - (maxIoName - pathStart));
ioName = nameStart + "..." + logPath;
}
}

public static boolean handleConfig(String logConfig) {
Expand All @@ -33,7 +38,7 @@ public void configViewer() throws IOException {
String userHost = logConfig.substring(5, pathStart);
String logPath = logConfig.substring(pathStart);

String lookback = (lookbackLines != 0) ? (" -n " + lookbackLines):"";
String lookback = (lookbackLines != 0) ? (" -n " + lookbackLines) : "";

logConfig = "ssh " + userHost + " tail" + lookback + " -f \"" + logPath + "\"";

Expand Down

0 comments on commit 79a5ef5

Please sign in to comment.