什么是pidcat

在Android日常开发中,对日志过滤是很有必要的,可是咱们在终端过滤日志的时候由于日志信息过多而看的目不暇接,而且很多时候,咱们只想过滤咱们自己使用进程的日志,可是当咱们的进程重启后,pid就变了,这时又需要从头获取进程pid,然后过滤,假如咱们想看两个或多个进程的日志就更费事,于是就产生了pidcat。

先上图看看作用

$pidcat toor

一个高效的Android终端日志过滤工具

如何使用

$pidcat –help

A logcat colored command which displays only source entries for processes of a specific application package.
Usage: pidcat [OPTIONS] [process]...  
Arguments:  
[process]...  
    Name of the process to be filtered  
Options:  
-t, --tag <tag>  
    The tag filter patterns  
--tag-width <tag_width>  
    Set the tag show width. must >= 10  
    [default: 20]  
-v, --revert-match <revert>  
    Selected lines are those not matching any of the specified patterns.  
-b, --buffer <buffer>  
    The buffer to filter  
    [default: main system]  
    [possible values: main, system, crash, radio, events, all]  
-c, --clear  
    Clear (flush) the entire log and exit  
-l, --level <level>  
    Filter log level  
    [default: V]  
    Possible values:  
    - V: Verbose  
    - D: Debug  
    - I: Info  
    - W: Warning  
    - E: Error  
    - F: Fatal  
-o, --output <output>  
    Writing logs to a file  
--color <color>  
    Display in highlighted color to match priority  
    [default: auto]  
    [possible values: auto, always, never]  
-i, --ignore-case  
    Ignore case  
-s <device>  
    Use device with given serial  
-h, --help  
    Print help (see a summary with '-h')  
-V, --version  
    Print version

其间tag和revert都支撑正则,如下命令能够过滤两个tag的日志

pidcat -t "ActivityManager|Debug"

两种装置方式

经过源码装置

这种方式适合一切操作体系

  • 装置rust开发环境
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
  • 下载源码
git clone https://github.com/borneygit/pidcat.git
cd pidcat
  • 装置
cargo install --path .

mac体系经过brew装置

brew tap borneygit/brew
brew install borneygit/brew/pidcat

项目是使用rust编写的,开放了获取adb logcat日志的接口能够在你的crate中直接使用。
在Rust项目的Cargo.toml中加入依靠

pidcat="0.2.1"

使用如下代码就能够获得处理封装好的android 终端日志了

use futures::StreamExt;
use pidcat::LogStream;  
use pidcat::source::*;  
#[tokio::main]  
async fn main() {  
    let source = ADBSource::new(None);  
    let mut logs: LogStream = source.source().await;  
    while let Some(r) = logs.next().await {  
        if let Ok(log) = r {  
        println!("{}", log);  
        }  
    }  
}

项目地址

github.com/borneygit/p…