Skip to content

Commit 34b2b04

Browse files
committed
add pidcat.go
1 parent ad7552c commit 34b2b04

3 files changed

Lines changed: 445 additions & 0 deletions

File tree

‎README.md‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- [x] support launch after install apk
1111
- [x] support `fa devices --json`
1212
- [x] support `fa shell`
13+
- [x] colorful logcat and filter with package name
1314
- [ ] install apk and auto click confirm
1415
- [.] check device health status
1516
- [ ] show current app
@@ -113,6 +114,27 @@ $ fa shell busybox ls
113114
$ adb shell /data/local/tmp/busybox ls
114115
```
115116

117+
### Pidcat (logcat)
118+
Current implementation is wrapper of [pidcat.py](https://github.com/JakeWharton/pidcat)
119+
So use this feature, you need python installed.
120+
121+
```bash
122+
$ fa help pidcat
123+
USAGE:
124+
fa pidcat [package-name ...]
125+
126+
OPTIONS:
127+
--current filter logcat by current running app
128+
--clear clear the entire log before running
129+
--min-level value, -l value Minimum level to be displayed {V,D,I,W,E,F}
130+
--tag value, -t value filter output by specified tag(s)
131+
--ignore-tag value, -i value filter output by ignoring specified tag(s)
132+
```
133+
134+
The pidcat is very beautiful.
135+
136+
![pidcat](https://github.com/JakeWharton/pidcat/raw/master/screen.png)
137+
116138
## Reference
117139
Articles
118140

@@ -123,6 +145,7 @@ Articles
123145
- [openstf/adbkit](https://github.com/openstf/adbkit)
124146
- [ADB Source Code](https://github.com/aosp-mirror/platform_system_core/blob/master/adb)
125147
- ADB Protocols [OVERVIEW.TXT](https://github.com/aosp-mirror/platform_system_core/blob/master/adb/OVERVIEW.TXT) [SERVICES.TXT](https://github.com/aosp-mirror/platform_system_core/blob/master/adb/SERVICES.TXT) [SYNC.TXT](https://github.com/aosp-mirror/platform_system_core/blob/master/adb/SYNC.TXT)
148+
- [JakeWharton/pidcat](https://github.com/JakeWharton/pidcat)
126149

127150
Libs might be useful
128151

‎main.go‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ import (
55
"errors"
66
"fmt"
77
"io"
8+
"io/ioutil"
89
"log"
910
"os"
1011
"os/exec"
12+
"path/filepath"
1113
"regexp"
1214
"runtime"
1315
"strings"
@@ -313,6 +315,66 @@ func main() {
313315
return err
314316
},
315317
},
318+
{
319+
Name: "pidcat",
320+
Usage: "logcat filter with package name",
321+
UsageText: "fa pidcat [package-name ...]",
322+
Flags: []cli.Flag{
323+
cli.BoolFlag{
324+
Name: "current",
325+
Usage: "filter logcat by current running app",
326+
},
327+
cli.BoolFlag{
328+
Name: "clear",
329+
Usage: "clear the entire log before running",
330+
},
331+
cli.StringFlag{
332+
Name: "min-level, l",
333+
Usage: "Minimum level to be displayed {V,D,I,W,E,F}",
334+
},
335+
cli.StringSliceFlag{
336+
Name: "tag, t",
337+
Usage: "filter output by specified tag(s)",
338+
},
339+
cli.StringSliceFlag{
340+
Name: "ignore-tag, i",
341+
Usage: "filter output by ignoring specified tag(s)",
342+
},
343+
},
344+
Action: func(ctx *cli.Context) error {
345+
serial, err := chooseOne()
346+
if err != nil {
347+
return err
348+
}
349+
faDir := filepath.Join(os.Getenv("HOME"), ".fa")
350+
if err := os.MkdirAll(faDir, 0755); err != nil {
351+
return err
352+
}
353+
pidcatPath := filepath.Join(faDir, "pidcat.py")
354+
err = ioutil.WriteFile(pidcatPath, []byte(pidcatCode), 0644)
355+
if err != nil {
356+
return err
357+
}
358+
args := []string{pidcatPath, "-s", serial}
359+
if ctx.Bool("current") {
360+
args = append(args, "--current")
361+
}
362+
if ctx.Bool("clear") {
363+
args = append(args, "--clear")
364+
}
365+
if ctx.String("min-level") != "" {
366+
args = append(args, "-l", ctx.String("min-level"))
367+
}
368+
for _, tag := range ctx.StringSlice("tag") {
369+
args = append(args, "-t", tag)
370+
}
371+
for _, ignore := range ctx.StringSlice("ignore-tag") {
372+
args = append(args, "-i", ignore)
373+
}
374+
args = append(args, ctx.Args()...)
375+
return runCommand("python", args...)
376+
},
377+
},
316378
{
317379
Name: "healthcheck",
318380
Usage: "check device health status",

0 commit comments

Comments
 (0)
⌂ 换网址