diff --git a/src/org/fakebelieve/netbeans/plugin/logviewer/FileLogViewer.java b/src/org/fakebelieve/netbeans/plugin/logviewer/FileLogViewer.java index b5f9d6d..70a1c9e 100644 --- a/src/org/fakebelieve/netbeans/plugin/logviewer/FileLogViewer.java +++ b/src/org/fakebelieve/netbeans/plugin/logviewer/FileLogViewer.java @@ -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) { @@ -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."); } - } \ No newline at end of file diff --git a/src/org/fakebelieve/netbeans/plugin/logviewer/LogViewer.java b/src/org/fakebelieve/netbeans/plugin/logviewer/LogViewer.java index f5a60b1..396e172 100644 --- a/src/org/fakebelieve/netbeans/plugin/logviewer/LogViewer.java +++ b/src/org/fakebelieve/netbeans/plugin/logviewer/LogViewer.java @@ -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; @@ -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; } @@ -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) { diff --git a/src/org/fakebelieve/netbeans/plugin/logviewer/LogViewerAction.java b/src/org/fakebelieve/netbeans/plugin/logviewer/LogViewerAction.java deleted file mode 100644 index 7fdee19..0000000 --- a/src/org/fakebelieve/netbeans/plugin/logviewer/LogViewerAction.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package org.fakebelieve.netbeans.plugin.logviewer; - -import java.util.HashMap; -import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; - -public class LogViewerAction { - - protected static final Logger log = Logger.getLogger(LogViewer.class.getName()); - protected Map values = new HashMap(); - - public static LogViewerAction getLogViewerAction(Map map) { - Object o = map.get("viewerAction"); - if (!(o instanceof LogViewerAction)) { - log.log(Level.SEVERE, "Received an invalid viewerAction type: {0}", o.getClass().getName()); - throw new IllegalArgumentException("Invalid viewerAction attribute. Has to be a 'newvalue' of type LogViewerAction."); - } - - LogViewerAction logViewer = (LogViewerAction) o; - log.log(Level.FINE, "Creating new action of type: {0}", logViewer.getClass().getName()); - - for (Object entry : map.entrySet()) { - Object key = ((Map.Entry) entry).getKey(); - - if ("instanceCreate".equals(key) || "viewerAction".equals(key)) { - continue; - } - - // we have a valid property, add it - Object value = ((Map.Entry) entry).getValue(); - logViewer.putValue((String) key, value); - - // log it - if (value == null) { - value = "null"; - } - log.log(Level.FINE, "Adding LogViewerAction attribute ''{0}''=''{1}'' ({2}).", - new Object[]{(String) key, value.toString(), logViewer.getClass().getName()}); - } - - return logViewer; - } - - public void viewLog(String config) { - LogViewer viewer = null; - if (FileLogViewer.handleConfig(config)) { - viewer = new FileLogViewer(config, getName()); - } else if (ProcessLogViewer.handleConfig(config)) { - viewer = new ProcessLogViewer(config, getName()); - } else if (SshLogViewer.handleConfig(config)) { - viewer = new SshLogViewer(config, getName()); - } - - if (viewer != null) { - viewer.setLookbackLines(Integer.parseInt((String) getValue("lookback"))); - viewer.setRefreshInterval(Integer.parseInt((String) getValue("refresh"))); - - try { - viewer.showLogViewer(); - } catch (java.io.IOException e) { - log.log(Level.SEVERE, "Showing log action failed.", e); - } - } - } - - public String getName() { - return (String) getValue("displayName"); - } - - public Object getValue(String key) { - return values.get(key); - } - - public void putValue(String key, Object value) { - values.put(key, value); - } -} diff --git a/src/org/fakebelieve/netbeans/plugin/logviewer/LogViewerButtonAction.java b/src/org/fakebelieve/netbeans/plugin/logviewer/LogViewerButtonAction.java index e492a78..9abd8fe 100644 --- a/src/org/fakebelieve/netbeans/plugin/logviewer/LogViewerButtonAction.java +++ b/src/org/fakebelieve/netbeans/plugin/logviewer/LogViewerButtonAction.java @@ -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; @@ -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 loadHistory() { List logHistory = new ArrayList(); @@ -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); + } } } } diff --git a/src/org/fakebelieve/netbeans/plugin/logviewer/ProcessLogViewer.java b/src/org/fakebelieve/netbeans/plugin/logviewer/ProcessLogViewer.java index ea3cf1e..75958be 100644 --- a/src/org/fakebelieve/netbeans/plugin/logviewer/ProcessLogViewer.java +++ b/src/org/fakebelieve/netbeans/plugin/logviewer/ProcessLogViewer.java @@ -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) { @@ -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."); } diff --git a/src/org/fakebelieve/netbeans/plugin/logviewer/SshLogViewer.java b/src/org/fakebelieve/netbeans/plugin/logviewer/SshLogViewer.java index 94d3439..7a985d9 100644 --- a/src/org/fakebelieve/netbeans/plugin/logviewer/SshLogViewer.java +++ b/src/org/fakebelieve/netbeans/plugin/logviewer/SshLogViewer.java @@ -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) { @@ -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 + "\"";