From c34084dd7abd66311915337f768a7c4977e65dae Mon Sep 17 00:00:00 2001 From: James Nylen Date: Sun, 26 Jun 2011 20:46:58 -0400 Subject: [PATCH 01/11] Fix whitespace --- coloredlogcat.py | 12 ----- proclogcat | 116 +++++++++++++++++++++++------------------------ 2 files changed, 58 insertions(+), 70 deletions(-) diff --git a/coloredlogcat.py b/coloredlogcat.py index a485360..6fddf75 100755 --- a/coloredlogcat.py +++ b/coloredlogcat.py @@ -121,15 +121,3 @@ def allocate_color(tag): print line if len(line) == 0: break - - - - - - - - - - - - diff --git a/proclogcat b/proclogcat index 937c784..500c07d 100755 --- a/proclogcat +++ b/proclogcat @@ -40,78 +40,78 @@ $| = 1; # the ActivityManager to tell us as the processes dies and starts. my $numPids = get_pids($trackingInfo); if ($numPids == 0) { - print "- waiting for process ", join(' or ', keys %$trackingInfo), " -\n"; + print "- waiting for process ", join(' or ', keys %$trackingInfo), " -\n"; } while () { - my $line = $_; - my ($level, $tag, $pid, $message) = $line =~ - m/^([A-Z])\/(.*?)\(\s*(\d+)\s*\): (.*)$/; - - chomp $message; - - if ($tag eq 'ActivityManager') { - if ($message =~ m/^Start proc (.*?) .*?: pid=(\d+) /) { - if (exists $trackingInfo->{$1}) { - $trackingInfo->{$1} = $2; - print $line; - } - } elsif ($message =~ m/Process (.*?) \(pid (\d+)\) has died./) { - if (exists $trackingInfo->{$1}) { - $trackingInfo->{$1} = -1; - print $line; - } - } - } elsif (in_list($pid, values %$trackingInfo)) { - print $line; - } + my $line = $_; + my ($level, $tag, $pid, $message) = $line =~ + m/^([A-Z])\/(.*?)\(\s*(\d+)\s*\): (.*)$/; + + chomp $message; + + if ($tag eq 'ActivityManager') { + if ($message =~ m/^Start proc (.*?) .*?: pid=(\d+) /) { + if (exists $trackingInfo->{$1}) { + $trackingInfo->{$1} = $2; + print $line; + } + } elsif ($message =~ m/Process (.*?) \(pid (\d+)\) has died./) { + if (exists $trackingInfo->{$1}) { + $trackingInfo->{$1} = -1; + print $line; + } + } + } elsif (in_list($pid, values %$trackingInfo)) { + print $line; + } } ############################################################################### sub in_list($@) { - my $needle = shift; - my @haystack = @_; - - foreach my $hay (@haystack) { - if ($hay eq $needle) { - return 1; - } - } - return 0; + my $needle = shift; + my @haystack = @_; + + foreach my $hay (@haystack) { + if ($hay eq $needle) { + return 1; + } + } + return 0; } sub get_pids { - my $info = shift; - my @ps = qx{adb shell ps}; - if (@ps == 0) { - return -1; - } - my @columns = split /\s+/, (shift @ps); - - # There's a "STATE" column slipped in between WCHAN and NAME that has no - # room for a column... - splice @columns, $#columns, 0, 'STATE'; - - my $numFound = 0; - - foreach (@ps) { - s/\s+$//; - my @data = split /\s+/, $_, scalar @columns; - my %row = map { $_ => (shift @data) } @columns; - - if (exists $info->{$row{NAME}}) { - $info->{$row{NAME}} = $row{PID}; - $numFound++; - } - } - - return $numFound; + my $info = shift; + my @ps = qx{adb shell ps}; + if (@ps == 0) { + return -1; + } + my @columns = split /\s+/, (shift @ps); + + # There's a "STATE" column slipped in between WCHAN and NAME that has no + # room for a column... + splice @columns, $#columns, 0, 'STATE'; + + my $numFound = 0; + + foreach (@ps) { + s/\s+$//; + my @data = split /\s+/, $_, scalar @columns; + my %row = map { $_ => (shift @data) } @columns; + + if (exists $info->{$row{NAME}}) { + $info->{$row{NAME}} = $row{PID}; + $numFound++; + } + } + + return $numFound; } sub usage { - my $prog = shift; - die <<"EOF" + my $prog = shift; + die <<"EOF" Usage: adb logcat | $0 Usually, `process-name' is usually the same as your package, but not From f0fca1c9064c66090bd6a08ba2b12697b2166807 Mon Sep 17 00:00:00 2001 From: James Nylen Date: Sun, 26 Jun 2011 20:49:06 -0400 Subject: [PATCH 02/11] Make proclogcat accept process name regexes instead of full names --- proclogcat | 61 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/proclogcat b/proclogcat index 500c07d..ba653e0 100755 --- a/proclogcat +++ b/proclogcat @@ -23,10 +23,11 @@ use Data::Dumper; @ARGV > 0 or usage($0); -# We support tracking multiple process names. Fill %trackingInfo keys with the -# process names, where the values are to be filled with the current pid for -# that process or -1 if it is presumed dead. -my $trackingInfo = { map { $_ => -1 } @ARGV }; +# We support tracking multiple process names. Fill @trackedNames with the +# process names to match (via regular expressions). The process IDs that we +# are currently tracking will be stored in %trackedPids. +my @trackedNames = @ARGV; +my %trackedPids = (); # Flush all writes immediately. This is necessary as we expect this script to # be placed between two other programs in a pipe which outputs text very slowly @@ -38,9 +39,9 @@ $| = 1; # Lookup the pids of the processes before we start. From then on, rely on # the ActivityManager to tell us as the processes dies and starts. -my $numPids = get_pids($trackingInfo); +my $numPids = get_pids(); if ($numPids == 0) { - print "- waiting for process ", join(' or ', keys %$trackingInfo), " -\n"; + print "- waiting for process ", join(' or ', @trackedNames), " -\n"; } while () { @@ -52,37 +53,26 @@ while () { if ($tag eq 'ActivityManager') { if ($message =~ m/^Start proc (.*?) .*?: pid=(\d+) /) { - if (exists $trackingInfo->{$1}) { - $trackingInfo->{$1} = $2; + my $match = match_name($1); + if (defined $match) { + $trackedPids{$2} = 1; print $line; } } elsif ($message =~ m/Process (.*?) \(pid (\d+)\) has died./) { - if (exists $trackingInfo->{$1}) { - $trackingInfo->{$1} = -1; + my $match = match_name($1); + if (defined $match) { + $trackedPids{$2} = 0; print $line; } } - } elsif (in_list($pid, values %$trackingInfo)) { + } elsif ($trackedPids{$pid}) { print $line; } } ############################################################################### -sub in_list($@) { - my $needle = shift; - my @haystack = @_; - - foreach my $hay (@haystack) { - if ($hay eq $needle) { - return 1; - } - } - return 0; -} - sub get_pids { - my $info = shift; my @ps = qx{adb shell ps}; if (@ps == 0) { return -1; @@ -100,8 +90,9 @@ sub get_pids { my @data = split /\s+/, $_, scalar @columns; my %row = map { $_ => (shift @data) } @columns; - if (exists $info->{$row{NAME}}) { - $info->{$row{NAME}} = $row{PID}; + my $match = match_name($row{NAME}); + if (defined $match) { + $trackedPids{$row{PID}} = 1; $numFound++; } } @@ -109,13 +100,25 @@ sub get_pids { return $numFound; } +sub match_name { + my $name = shift; + my $match = undef; + foreach (@trackedNames) { + $match = $_ if $_ and $name =~ $_; + } + return $match; +} + sub usage { my $prog = shift; die <<"EOF" -Usage: adb logcat | $0 +Usage: adb logcat | $0 [ ...] + +Process names will be matched against the given regular expression(s), +and only the matching processes will be shown in the output. -Usually, `process-name' is usually the same as your package, but not -necessarily. To make sure, type `adb shell ps' and look through the list. +To find processes you're interested in, type `adb shell ps' and look +through the list. EOF } From faf5e0654a934342b16c9864dca6e5d44864a69d Mon Sep 17 00:00:00 2001 From: James Nylen Date: Sun, 26 Jun 2011 20:46:29 -0400 Subject: [PATCH 03/11] Expand tag type names --- coloredlogcat.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/coloredlogcat.py b/coloredlogcat.py index 6fddf75..7c79291 100755 --- a/coloredlogcat.py +++ b/coloredlogcat.py @@ -80,6 +80,14 @@ def allocate_color(tag): "E": format(fg=RED, bold=True), } +TAGTYPENAMES = { + "V": "Verb ", + "D": "Debug", + "I": "Info ", + "W": "WARN ", + "E": "ERROR" +} + retag = re.compile("^([A-Z])/([^\(]+)\(([^\)]+)\): (.*)$") # to pick up -d or -e @@ -104,7 +112,7 @@ def allocate_color(tag): # write out tagtype colored edge if not tagtype in TAGTYPES: break - linebuf.write("%s%s%s" % (TAGTYPES[tagtype], tagtype, format(reset=True))) + linebuf.write("%s%s%s" % (TAGTYPES[tagtype], TAGTYPENAMES[tagtype], format(reset=True))) color = allocate_color(tag) linebuf.write(" / %s%s%s" % (format(fg=color, bold=True), tag, format(reset=True))) From ad7b754c88813d28250a09ae00823ebc2dae92b4 Mon Sep 17 00:00:00 2001 From: James Nylen Date: Sun, 26 Jun 2011 20:50:33 -0400 Subject: [PATCH 04/11] Show usage if STDIN is a terminal --- proclogcat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proclogcat b/proclogcat index ba653e0..d521db1 100755 --- a/proclogcat +++ b/proclogcat @@ -21,7 +21,7 @@ use Data::Dumper; ############################################################################### -@ARGV > 0 or usage($0); +@ARGV > 0 and not -t STDIN or usage($0); # We support tracking multiple process names. Fill @trackedNames with the # process names to match (via regular expressions). The process IDs that we From 7998bc7769a8639e99cf44d0b48a6bcc4756195d Mon Sep 17 00:00:00 2001 From: James Nylen Date: Sun, 26 Jun 2011 20:58:11 -0400 Subject: [PATCH 05/11] Add super-logcat.sh wrapper script --- super-logcat.sh | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100755 super-logcat.sh diff --git a/super-logcat.sh b/super-logcat.sh new file mode 100755 index 0000000..e7bb9a8 --- /dev/null +++ b/super-logcat.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +cd "$(dirname "$0")" # if run from another directory + +[ -z "$1" ] && "$0" '.*' && exit + +adb logcat | ./proclogcat "$@" | ./coloredlogcat.py From 471bd1ded7b12ca92787a72f7a76b45de54c80a2 Mon Sep 17 00:00:00 2001 From: James Nylen Date: Sun, 26 Jun 2011 21:05:27 -0400 Subject: [PATCH 06/11] Make super-logcat.sh work if run from a symlink --- super-logcat.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/super-logcat.sh b/super-logcat.sh index e7bb9a8..8b46d1b 100755 --- a/super-logcat.sh +++ b/super-logcat.sh @@ -1,6 +1,10 @@ #!/bin/sh -cd "$(dirname "$0")" # if run from another directory +me=$0 +link=$(readlink "$me") +[ ! -z "$link" ] && me=$link + +cd "$(dirname "$me")" [ -z "$1" ] && "$0" '.*' && exit From 3cf3244d8226952a214185c9d3a3eda064da36c1 Mon Sep 17 00:00:00 2001 From: James Nylen Date: Sun, 26 Jun 2011 21:11:27 -0400 Subject: [PATCH 07/11] Add readme --- README.mkdn | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 README.mkdn diff --git a/README.mkdn b/README.mkdn new file mode 100644 index 0000000..b61652a --- /dev/null +++ b/README.mkdn @@ -0,0 +1,12 @@ +What is this? +------------- + +This is a set of scripts to enhance and filter Android's logcat output. + +Usually you'll want to run: + +`./super-logcat.sh ` + +So, if your process name is `com.example.myapp`, then running `./super-logcat.sh example` will show all messages related to your application. + +Running the `super-logcat.sh` script with no arguments will display the logcat output from every process, piped through the same formatting and coloring algorithm. From 67aa4e06bee17d572645e8b89f45c903b975d105 Mon Sep 17 00:00:00 2001 From: James Nylen Date: Sun, 26 Jun 2011 21:21:01 -0400 Subject: [PATCH 08/11] Clean up match_name function and usage --- proclogcat | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/proclogcat b/proclogcat index d521db1..423c1a9 100755 --- a/proclogcat +++ b/proclogcat @@ -53,14 +53,12 @@ while () { if ($tag eq 'ActivityManager') { if ($message =~ m/^Start proc (.*?) .*?: pid=(\d+) /) { - my $match = match_name($1); - if (defined $match) { + if (match_name($1)) { $trackedPids{$2} = 1; print $line; } } elsif ($message =~ m/Process (.*?) \(pid (\d+)\) has died./) { - my $match = match_name($1); - if (defined $match) { + if (match_name($1)) { $trackedPids{$2} = 0; print $line; } @@ -102,11 +100,10 @@ sub get_pids { sub match_name { my $name = shift; - my $match = undef; foreach (@trackedNames) { - $match = $_ if $_ and $name =~ $_; + return 1 if $_ and $name =~ $_; } - return $match; + return 0; } sub usage { From 81689d4c7796764f2eed103819cbaefd63464be0 Mon Sep 17 00:00:00 2001 From: James Nylen Date: Sun, 26 Jun 2011 21:29:28 -0400 Subject: [PATCH 09/11] Oops (fix previous commit) --- proclogcat | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/proclogcat b/proclogcat index 423c1a9..1558af7 100755 --- a/proclogcat +++ b/proclogcat @@ -88,8 +88,7 @@ sub get_pids { my @data = split /\s+/, $_, scalar @columns; my %row = map { $_ => (shift @data) } @columns; - my $match = match_name($row{NAME}); - if (defined $match) { + if (match_name($row{NAME})) { $trackedPids{$row{PID}} = 1; $numFound++; } From 5af43cde11623125451accc7b9fadd7dbd2cda12 Mon Sep 17 00:00:00 2001 From: molikuner Date: Sun, 15 Jul 2018 04:21:43 +0200 Subject: [PATCH 10/11] update to "new" format of logcat but keep old format available * show help when not using proclogcat in pipe * the format of logcat has been changed * the column state has now the name 'S' -> don't need to add it * removed unnecessary code in coloredlogcat.py * replacing tagtypes with names - i'm using android 8.1 currently - this means that i could not test the old format --- coloredlogcat.py | 44 +++++++++++++++++++++++++++++--------------- proclogcat | 23 +++++++++++++++++------ 2 files changed, 46 insertions(+), 21 deletions(-) diff --git a/coloredlogcat.py b/coloredlogcat.py index 856f314..7509bc4 100755 --- a/coloredlogcat.py +++ b/coloredlogcat.py @@ -48,6 +48,7 @@ def colorToFormat(color): LAST_USED = map(colorToFormat, [RED,GREEN,YELLOW,BLUE,MAGENTA,CYAN,WHITE]) KNOWN_TAGS = { "dalvikvm": format(fg=BLACK, bold=True), + "AndroidRuntime": format(fg=BLACK, bold=True), "Process": format(fg=YELLOW, bold=True), "ActivityManager": format(fg=CYAN, bold=True), "ActivityThread": format(fg=CYAN, bold=True), @@ -67,15 +68,6 @@ def allocate_color(tag): return color -RULES = { - #re.compile(r"([\w\.@]+)=([\w\.@]+)"): r"%s\1%s=%s\2%s" % (format(fg=BLUE), format(fg=GREEN), format(fg=BLUE), format(reset=True)), -} - -TAGTYPE_WIDTH = 1 -TAG_WIDTH = 20 -PROCESS_WIDTH = 8 # 8 or -1 -HEADER_SIZE = TAGTYPE_WIDTH + 1 + TAG_WIDTH + 1 + PROCESS_WIDTH + 1 - TAGTYPES = { "V": "", "D": format(fg=BLUE, bold=True), @@ -84,7 +76,17 @@ def allocate_color(tag): "E": format(fg=RED, bold=True), } + +TAGTYPENAMES = { + "V": "Verb ", + "D": "Debug", + "I": "Info ", + "W": "WARN ", + "E": "ERROR" +} + retag = re.compile("^([A-Z])/(.+?)\((\s*\d+)\): (.*)$") +newRetag = re.compile("^([0-9-\s:.]+?)\s+(\d+)\s+(\d+)\s+([A-Z])\s+(.*?)\s*: (.*)$") # to pick up -d or -e adb_args = ' '.join(sys.argv[1:]) @@ -102,26 +104,38 @@ def allocate_color(tag): break match = retag.match(line) + newMatch = newRetag.match(line) if not match is None: + # level, tag, pid, msg tagtype, tag, owner, message = match.groups() linebuf = StringIO.StringIO() # write out tagtype colored edge if not tagtype in TAGTYPES: break - linebuf.write("%s%s%s" % (TAGTYPES[tagtype], tagtype, format(reset=True))) + linebuf.write("%s%s%s" % (TAGTYPES[tagtype], TAGTYPENAMES[tagtype], format(reset=True))) colorfmt = allocate_color(tag) linebuf.write(" / %s%s%s" % (colorfmt, tag, format(reset=True))) linebuf.write(" (%s): " % owner) - # format tag message using rules - for matcher in RULES: - replace = RULES[matcher] - message = matcher.sub(replace, message) - linebuf.write("%s%s%s" % (colorfmt, message, format(reset=True))) line = linebuf.getvalue() + elif not newMatch is None: + time, owner, ppid, tagtype, tag, message = newMatch.groups() + if not tagtype in TAGTYPES: break + linebuf = StringIO.StringIO() + linebuf.write("%s %05s | %05s" % (time, owner, ppid)) + + + # write out tagtype colored edge + linebuf.write(" %s%s%s" % (TAGTYPES[tagtype], TAGTYPENAMES[tagtype], format(reset=True))) + + colorfmt = allocate_color(tag) + linebuf.write(" / %s%s%s: " % (colorfmt, tag, format(reset=True))) + + linebuf.write("%s%s%s" % (colorfmt, message, format(reset=True))) + line = linebuf.getvalue() print line if len(line) == 0: break diff --git a/proclogcat b/proclogcat index 5266803..64a8bdf 100755 --- a/proclogcat +++ b/proclogcat @@ -21,7 +21,7 @@ use Data::Dumper; ############################################################################### -@ARGV > 0 or usage($0); +@ARGV > 0 and not -t STDIN or usage($0); # We support tracking multiple process names. Fill %trackingInfo keys with the # process names, where the values are to be filled with the current pid for @@ -45,8 +45,12 @@ if ($numPids == 0) { while () { my $line = $_; - my ($level, $tag, $pid, $message) = $line =~ - m/^([A-Z])\/(.*?)\(\s*(\d+)\s*\): (.*)$/; + my ($time, $pid, $ppid, $level, $tag, $message) = $line =~ + m/^([0-9-\s:.]+)\s+(\d+)\s+(\d+)\s+([A-Z])\s+(.*?)\s*: (.*)$/; + if ($pid == 0) { + ($level, $tag, $pid, $message) = $line =~ + m/^([A-Z])\/(.*?)\(\s*(\d+)\s*\): (.*)$/; + } chomp $message; @@ -66,6 +70,11 @@ while () { $trackingInfo->{$1} = -1; print $line; } + } elsif ($message =~ m/Killing (\d+):(.*?)\//) { + if (exists $trackingInfo->{$1}) { + $trackingInfo->{$2} = $1; + print $line; + } } } elsif (in_list($pid, values %$trackingInfo)) { print $line; @@ -94,9 +103,11 @@ sub get_pids { } my @columns = split /\s+/, (shift @ps); - # There's a "STATE" column slipped in between WCHAN and NAME that has no - # room for a column... - splice @columns, $#columns, 0, 'STATE'; + if (! in_list("S", @columns)) { + # There's a "STATE" column slipped in between WCHAN and NAME that has no + # room for a column name... + splice @columns, $#columns, 0, 'STATE'; + } my $numFound = 0; From 3065701b343c54c49807c68e36241c54c3b74169 Mon Sep 17 00:00:00 2001 From: molikuner Date: Wed, 25 Jul 2018 02:50:19 +0200 Subject: [PATCH 11/11] fixes and improvments * also log messges with a given tag * rework README * fix some problems with coloredlogcat.py not exiting (propably merging error) * do not change the dir when using super-logcat.sh --- README.md | 26 ++++++++++++++++++++++++++ README.mkdn | 12 ------------ coloredlogcat.py | 11 ++++++----- proclogcat | 21 ++++++++++++++------- super-logcat.sh | 17 ++++++++++------- 5 files changed, 56 insertions(+), 31 deletions(-) create mode 100644 README.md delete mode 100644 README.mkdn diff --git a/README.md b/README.md new file mode 100644 index 0000000..6847fa9 --- /dev/null +++ b/README.md @@ -0,0 +1,26 @@ +What is this? +------------- + +This is a set of scripts to enhance your development time with adb. + +* LOGCAT: + +`./super-logcat.sh ` + +So, if your process name is `com.example.myapp`, then running `./super-logcat.sh com.example` will show all messages related to your application. + +Running the `super-logcat.sh` script with no arguments will display the logcat output from every process, piped through the same formatting and coloring algorithm. + + +* DEVICES: + +`./pickdevice.pl` + +This will help you easily select the device to run the commands on. This is usefull when using multiple devices/emulators at the same time. + + +* METHOD_ANALYSING + +`./dexdumpmethods.sh ` + +You will see all methods in this package. It is usefull to pipe it into `wc -l` to see an overall number of functions. diff --git a/README.mkdn b/README.mkdn deleted file mode 100644 index b61652a..0000000 --- a/README.mkdn +++ /dev/null @@ -1,12 +0,0 @@ -What is this? -------------- - -This is a set of scripts to enhance and filter Android's logcat output. - -Usually you'll want to run: - -`./super-logcat.sh ` - -So, if your process name is `com.example.myapp`, then running `./super-logcat.sh example` will show all messages related to your application. - -Running the `super-logcat.sh` script with no arguments will display the logcat output from every process, piped through the same formatting and coloring algorithm. diff --git a/coloredlogcat.py b/coloredlogcat.py index bf24472..04213a6 100755 --- a/coloredlogcat.py +++ b/coloredlogcat.py @@ -48,7 +48,7 @@ def colorToFormat(color): LAST_USED = map(colorToFormat, [RED,GREEN,YELLOW,BLUE,MAGENTA,CYAN,WHITE]) KNOWN_TAGS = { "dalvikvm": format(fg=BLACK, bold=True), - "AndroidRuntime": format(fg=BLACK, bold=True), + "AndroidRuntime": format(fg=MAGENTA, bold=True), "Process": format(fg=YELLOW, bold=True), "ActivityManager": format(fg=CYAN, bold=True), "ActivityThread": format(fg=CYAN, bold=True), @@ -85,7 +85,7 @@ def allocate_color(tag): "E": "ERROR" } -retag = re.compile("^([A-Z])/([^\(]+)\(([^\)]+)\): (.*)$") +retag = re.compile("^([A-Z])/(.+?)\((\s*\d+)\): (.*)$") newRetag = re.compile("^([0-9-\s:.]+?)\s+(\d+)\s+(\d+)\s+([A-Z])\s+(.*?)\s*: (.*)$") # to pick up -d or -e @@ -102,6 +102,7 @@ def allocate_color(tag): line = input.readline().rstrip() except KeyboardInterrupt: break + if len(line) == 0: break match = retag.match(line) newMatch = newRetag.match(line) @@ -113,12 +114,12 @@ def allocate_color(tag): if not tagtype in TAGTYPES: break linebuf.write("%s%s%s" % (TAGTYPES[tagtype], TAGTYPENAMES[tagtype], format(reset=True))) - color = allocate_color(tag) - linebuf.write(" / %s%s%s" % (format(fg=color, bold=True), tag, format(reset=True))) + colorfmt = allocate_color(tag) + linebuf.write(" / %s%s%s" % (colorfmt, tag, format(reset=True))) linebuf.write(" (%s): " % owner) - linebuf.write("%s%s%s" % (color, message, format(reset=True))) + linebuf.write("%s%s%s" % (colorfmt, message, format(reset=True))) line = linebuf.getvalue() elif not newMatch is None: time, owner, ppid, tagtype, tag, message = newMatch.groups() diff --git a/proclogcat b/proclogcat index df59199..f558eff 100755 --- a/proclogcat +++ b/proclogcat @@ -53,6 +53,12 @@ while () { m/^([A-Z])\/(.*?)\(\s*(\d+)\s*\): (.*)$/; } + # print line if does not match the regex + if ($pid == 0 && $tag == 0) { + print $line; + next; + } + chomp $message; if ($tag eq 'ActivityManager') { @@ -68,16 +74,16 @@ while () { } } elsif ($message =~ m/Process (.*?) \(pid (\d+)\) has died./) { if (match_name($1)) { - $trackedPids{$2} = 0; + delete $trackedPids{$2}; print $line; } } elsif ($message =~ m/Killing (\d+):(.*?)\//) { if (match_name($2)) { - $trackedPids{$1} = 0; + delete $trackedPids{$1}; print $line; } } - } elsif ($trackedPids{$pid}) { + } elsif ($trackedPids{$pid} || in_list($tag, @trackedNames)) { print $line; } } @@ -97,7 +103,7 @@ sub in_list($@) { } sub get_pids { - my @ps = qx{adb shell ps}; + my @ps = qx{adb wait-for-device && adb shell ps}; if (@ps == 0) { return -1; } @@ -136,13 +142,14 @@ sub match_name { sub usage { my $prog = shift; die <<"EOF" -Usage: adb logcat | $0 [ ...] +Usage: adb logcat | $0 [ ...] Process names will be matched against the given regular expression(s), and only the matching processes will be shown in the output. +Or the tag is equals to the it and it will be shown. -To find processes you're interested in, type `adb shell ps' and look -through the list. +Usually, `process-name' is usually the same as your package, but not +necessarily. To make sure, type `adb shell ps' and look through the list. EOF } diff --git a/super-logcat.sh b/super-logcat.sh index 8b46d1b..9465886 100755 --- a/super-logcat.sh +++ b/super-logcat.sh @@ -1,11 +1,14 @@ -#!/bin/sh +#!/usr/bin/env bash -me=$0 -link=$(readlink "$me") -[ ! -z "$link" ] && me=$link +if [ ! "$*" ]; then + "$0" ".+" + exit $? +fi -cd "$(dirname "$me")" +dir=`dirname "$0"` -[ -z "$1" ] && "$0" '.*' && exit +if [ "`readlink $0`" ]; then + dir=`dirname "$(readlink $0)"` +fi -adb logcat | ./proclogcat "$@" | ./coloredlogcat.py +adb logcat | "$dir/proclogcat" "$@" | "$dir/coloredlogcat.py"