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

pidcat是一个用于Android开发的命令行工具,它能方便地过滤和显示特定应用进程的日志,支持正则表达式过滤标签,且可在进程重启或查看多进程日志时提供便利。该工具由Rust编写,可以通过源码或在macOS上通过brew安装,还可以在Rust项目中作为库使用。
摘要由CSDN通过智能技术生成

什么是pidcat

在Android日常开发中,对日志过滤是很有必要的,但是我们在终端过滤日志的时候因为日志信息过多而看的眼花缭乱,而且很多时候,我们只想过滤我们自己应用进程的日志,但是当我们的进程重启后,pid就变了,这时又需要重新获取进程pid,然后过滤,如果我们想看两个或多个进程的日志就更麻烦,于是就产生了pidcat。

先上图看看效果

$pidcat toor

在这里插入图片描述

如何使用

$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);  
        }  
    }  
}

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值