Index: shell/log/src/main/java/org/apache/karaf/shell/log/DisplayException.java =================================================================== --- shell/log/src/main/java/org/apache/karaf/shell/log/DisplayException.java (revision 1092477) +++ shell/log/src/main/java/org/apache/karaf/shell/log/DisplayException.java (working copy) @@ -18,11 +18,15 @@ import org.ops4j.pax.logging.spi.PaxLoggingEvent; import org.apache.karaf.shell.console.OsgiCommandSupport; +import org.apache.felix.gogo.commands.Argument; import org.apache.felix.gogo.commands.Command; @Command(scope = "log", name = "display-exception", description = "Displays the last occurred exception from the log.") public class DisplayException extends OsgiCommandSupport { + @Argument(index = 0, name = "logger", description = "The name of the logger. This can be ROOT, ALL, or the name of a logger specified in the org.ops4j.pax.logger.cfg file.", required = false, multiValued = false) + String logger; + protected LruList events; public LruList getEvents() { @@ -37,9 +41,17 @@ PaxLoggingEvent throwableEvent = null; Iterable le = events.getElements(Integer.MAX_VALUE); for (PaxLoggingEvent event : le) { - if (event.getThrowableStrRep() != null) { + // if this is an exception, and the log is the same as the requested log, + // then save this exception and continue iterating from oldest to newest + if ((event.getThrowableStrRep() != null) + &&(logger != null) + &&(checkIfFromRequestedLog(event))) { throwableEvent = event; - // Do not break, as we iterate from the oldest to the newest event + // Do not break, as we iterate from the oldest to the newest event + } // now check if there has been no log passed in, and if this is an exception + // then save this exception and continue iterating from oldest to newest + else if ((event.getThrowableStrRep() != null)&&(logger == null)) { + throwableEvent = event; } } if (throwableEvent != null) { @@ -50,5 +62,10 @@ } return null; } + + protected boolean checkIfFromRequestedLog(PaxLoggingEvent event) { + System.out.println("In check block for " + logger + " checking against " + event.getLoggerName()); + return (event.getLoggerName().lastIndexOf(logger)>=0) ? true : false; + } } Index: shell/log/src/main/java/org/apache/karaf/shell/log/DisplayLog.java =================================================================== --- shell/log/src/main/java/org/apache/karaf/shell/log/DisplayLog.java (revision 1092477) +++ shell/log/src/main/java/org/apache/karaf/shell/log/DisplayLog.java (working copy) @@ -21,6 +21,7 @@ import org.apache.karaf.shell.log.layout.PatternConverter; import org.apache.karaf.shell.log.layout.PatternParser; import org.apache.karaf.shell.console.OsgiCommandSupport; +import org.apache.felix.gogo.commands.Argument; import org.apache.felix.gogo.commands.Option; import org.apache.felix.gogo.commands.Command; import org.ops4j.pax.logging.spi.PaxAppender; @@ -41,6 +42,9 @@ @Option(name = "--no-color", description="Disable syntax coloring of log events", required = false, multiValued = false) protected boolean noColor; + @Argument(index = 0, name = "logger", description = "The name of the logger. This can be ROOT, ALL, or the name of a logger specified in the org.ops4j.pax.logger.cfg file.", required = false, multiValued = false) + String logger; + protected String pattern; protected LruList events; protected String fatalColor; @@ -131,13 +135,22 @@ Iterable le = events.getElements(entries == 0 ? Integer.MAX_VALUE : entries); for (PaxLoggingEvent event : le) { - if (event != null) { - display(cnv, event, out); + if ((logger != null) && + (event != null)&& + (checkIfFromRequestedLog(event))) { + display(cnv, event, out); + } + else if ((event != null)&&(logger == null)){ + display(cnv, event, out); } } out.println(); return null; } + + protected boolean checkIfFromRequestedLog(PaxLoggingEvent event) { + return (event.getLoggerName().lastIndexOf(logger)>=0) ? true : false; + } protected void display(PatternConverter cnv, PaxLoggingEvent event, PrintStream stream) { String color = getColor(event); Index: shell/log/src/main/java/org/apache/karaf/shell/log/LogTail.java =================================================================== --- shell/log/src/main/java/org/apache/karaf/shell/log/LogTail.java (revision 1092477) +++ shell/log/src/main/java/org/apache/karaf/shell/log/LogTail.java (working copy) @@ -17,8 +17,6 @@ package org.apache.karaf.shell.log; import java.io.PrintStream; -import java.util.LinkedList; -import java.util.Queue; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; @@ -30,26 +28,42 @@ @Command(scope = "log", name = "tail", description = "Continuously display log entries.") public class LogTail extends DisplayLog { - + protected Object doExecute() throws Exception { final PatternConverter cnv = new PatternParser(overridenPattern != null ? overridenPattern : pattern).parse(); final PrintStream out = System.out; Iterable le = events.getElements(entries == 0 ? Integer.MAX_VALUE : entries); + System.out.println("Going into First Loop " + logger); for (PaxLoggingEvent event : le) { - display(cnv, event, out); + if ((logger != null) && + (event != null)&& + (checkIfFromRequestedLog(event))) { + display(cnv, event, out); + } + else if ((event != null)&&(logger == null)){ + display(cnv, event, out); + } } // Tail final BlockingQueue queue = new LinkedBlockingQueue(); PaxAppender appender = new PaxAppender() { public void doAppend(PaxLoggingEvent event) { - queue.add(event); + queue.add(event); } }; try { events.addAppender(appender); for (;;) { - display(cnv, queue.take(), out); + PaxLoggingEvent event = queue.take(); + if ((logger != null) && + (event != null)&& + (checkIfFromRequestedLog(event))) { + display(cnv, event, out); + } + else if ((event != null)&&(logger == null)){ + display(cnv, event, out); + } } } catch (InterruptedException e) { // Ignore