Fixed onos-log-query to properly exclude stack traces and merge logs.

Change-Id: Idd3b915a8dc4c75a0da03445d759753450f9fe25
(cherry picked from commit bfcc57bb75394f9d4ea78ffa6046ce6cbd147fac)
diff --git a/tools/package/runtime/bin/onos-log-query b/tools/package/runtime/bin/onos-log-query
index 5f45375..3985d8b 100755
--- a/tools/package/runtime/bin/onos-log-query
+++ b/tools/package/runtime/bin/onos-log-query
@@ -24,15 +24,15 @@
     exit 1
 }
 
-name=query      # default name
+name=query  # default name
 onlyts=0
 
 while getopts n:f:t:x?h o; do
     case "$o" in
+        x) onlyts=1;;
         n) name="$OPTARG";;
         f) from="$OPTARG";;
         t) to="$OPTARG";;
-        x) onlyts=1;;
         *) usage;;
     esac
 done
@@ -40,18 +40,17 @@
 let OPC=$OPTIND-1
 shift $OPC
 
-[ "$name" = "karaf" ] && echo "Name cannot be karaf" && usage
+[ "$name" = "karaf" ] && echo "Name cannot be 'karaf'!" && usage
 
 function stitchLogs {
-    awk -v from="${from}" -v to="${to}" -v onlyts=${onlyts} \
-        -v TS="[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2},[0-9]{3}" '
-        BEGIN { on = 0; FS="|"; }
-        TS {
+    awk -v onlyts=${onlyts} -v from="${from}" -v to="${to}" '
+        BEGIN { on = !onlyts && from == "" && to == ""; FS="|"; }
+        /^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2},[0-9]{3}/ {
             on = (from == "" || $1 >= from) && (to == "" || $1 <= to);
             if (on) { print $0; }
             next;
         }
-        { if (on && !onlyts) { print $0; } }
+        { if (on && !onlyts) { print $0; }}
     ' $(ls -r1 karaf.log*) > ${name}.log
 }
 
@@ -59,12 +58,13 @@
     pushd $1 &>/dev/null
     stitchLogs
     popd &>/dev/null
+    echo ${1}/${name}.log
 }
 
 if [ $# -eq 1 -a -d "$1" ]; then
     stitchNodeLogs $1
 elif [ $# -ge 1 ]; then
-    echo "No node directory for $1" >&2
+    echo "No node directory for '$1'!" >&2
     usage
 elif ls karaf.log &>/dev/null; then
     stitchLogs
@@ -74,5 +74,8 @@
     done
     wait
     awk '{ print FILENAME " | " $0; }' */${name}.log | \
-        sed "s:/${name}.log::" | sort -t\| -k2,2 > ${name}.log
+        sed "s:/${name}.log::" | \
+        egrep '[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2},[0-9]{3}' | \
+        sort -t\| -k2,2 > ${name}.log
+    echo ${name}.log
 fi