Giter Club home page Giter Club logo

rogcat's Introduction

CI crates.io Release License

rogcat

...is a adb logcat wrapper. The Android Debugging Bridge (adb) is the default way to interact with a Android device during development. The logcat subcommand of adb allows access to Androids internal log buffers. rogcat tries to give access to those logs in a convenient way including post processing capabilities. The main feature probably is a painted and reformatted view. rogcat can read logs from

  • running adb logcat (default)
  • a custom command (stdout, stderr)
  • one or multiple files
  • stdin
  • connect to TCP port
  • A SocketCAN CAN device (Linux only)

The processing steps within a rogcat run include parsing of the input stream and applying filters (if provided). rogcat comes with a set of implemented in and output formats:

  • csv: Comma separated values
  • raw: Record (line) as captured
  • html: A static single page html with a static table. This option cannot be used as input format. The page layout needs some love...
  • human: A human friendly colored column based format. See screenshot
  • json: Single line JSON

Except the human and html format the output of rogcat is parseable by rogcat.

Screenshot

Examples

The following examples show a subset of rogcat's features. Please read --help!

Live

Capture logs from a connected device and display unconditionally. Unless configurated otherwise, Rogcat runs adb logcat -b main -b events -b crash -b kernel:

rogcat

Write captured logs to testrun.log:

rogcat -o testrun.log

Write captured logs to file ./trace/testrun-XXX.log by starting a new file every 1000 lines. If ./trace is not present it is created:

rogcat -o ./trace/testrun.log -n 1000 or rogcat -o ./trace/testrun.log -n 1k

stdin

Process stdout and stderr of command:

rogcat command or command | rogcat -

Filter

Display logs from adb logcat and filter on records where the tag matches ^ABC.* along with not X and the message includes pattern:

rogcat -t "^ADB.*" -t \!X -m pattern

The Read all files matching trace* in alphanumerical order and dump lines matching hmmm to /tmp/filtered:

rogcat -i trace* -m hmmm -o /tmp/filtered

Check the --message and --highlight options in the helptext.

TCP

To connect via TCP to some host run something like:

rogcat tcp://traceserver:1234

SocketCAN

To open a SocketCAN device and read frames run:

rogcat can://can0

SocketCAN is a Linux only thing.

Bugreport

Capture a Android bugreport. This only works for Android version prior 7:

rogcat bugreport

Capture a Android bugreport and write (zipped) to bugreport.zip:

rogcat bugreport -z bugreport.zip

Log

Write message "some text" into the device log buffer (e.g annotations during manual testing):

rogcat log "some text"

Set level and tag or read from stdin:

rogcat-log
Add log message(s) log buffer

USAGE:
    rogcat log [OPTIONS] [MESSAGE]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -l, --level <LEVEL>    Log on level [values: trace, debug, info, warn, error, fatal, assert, T, D, I, W, E, F, A]
    -t, --tag <TAG>        Log tag

ARGS:
    <MESSAGE>    Log message. Pass "-" to capture from stdin'

Installation

Building rogcat requires Rust 2018 edition:

cargo install --path .

or grab one of the binary releases on the GitHub page.

On Debian based systems the package libudev-dev (and it's dependencies) is required for building.

Configuration

When rogcat runs without any command supplied it defaults to running adb logcat -b all. The following options can be overwritten in the rogcat config file config.toml. The location of the config file is platform specific:

  • MacOS: $HOME/Library/Preferences/rogcat/config.toml
  • Linux: $HOME/.config/rogcat/config.toml
  • Windows: %HOME%/AppData/Roaming/rogcat/config.toml

Restart

By default rogcat restarts adb logcat when that one exits. This is intentional behavior to make rogcat reconnect on device power cycles or disconnect/reconnects. A Windows 7 bug prevents rogcat from restarting adb. Place restart = false in the configuration file mentioned above to make rogcat exit when adb exits.

Buffer

The default behavior of rogcat is to dump all logcat buffers. This can be overwritten by selecting specific buffers in the rogcat configuration file. e.g:

buffer = ["main", "events"]

Terminal settings

Some parameters of the human format are adjustable via the config file:

terminal_tag_width = 20
terminal_show_date = false
terminal_hide_timestamp = true
terminal_color = never
terminal_no_dimm = true
terminal_bright_colors = false

Profiles

Optionally rogcat reads a (toml formated) configuration file if present. This configuration may include tracing profiles ('-p') and settings. The possible options in the configuration file are a subset of the command line options. The configuration file is read from the location set in the environment variable ROGCAT_PROFILES or a fixed pathes depending on your OS:

  • MacOS: $HOME/Library/Preferences/rogcat/profiles.toml
  • Linux: $HOME/.config/rogcat/profiles.toml
  • Windows: %HOME%/AppData/Roaming/rogcat/profiles.toml

The environment variable overrules the default path. See rogcat profiles --help or rogcat profiles --examples.

Example:

[profile.a]
comment = "Messages starting with A or a"
message_ignore_case = ["^A.*"]

[profile.B]
comment = "Messages starting with B"
message = ["^B.*"]

[profile.ABC]
extends = ["A", "B"]
comment = "Profiles A, B plus the following filter (^C.*)"
message = ["^C.*"]

[profile."Comments are optional"]
tag = ["rogcat"]

[profile.complex]
comment = "Profiles can be complex. This one is probably very useless."
highlight = ["blah"]
message = ["^R.*", "!^A.*", "!^A.*"]
tag = ["b*", "!adb"]

[profile."W hitespace"]
comment = "Profile names can contain whitespaces. Quote on command line..."

[profile.rogcat]
comment = "Only tag \"rogcat\""
tag = ["^rogcat$"]

[profile.default]
comment = "Default profile"

To check your setup, run rogcat profiles --list and select a profile for a run by passing the -p/--profile option.

You can create a special profile named default which will be used when no other profile is selected on the command line.

Usage

rogcat 0.4.3-alpha.0
Felix Obenhuber <[email protected]>
A 'adb logcat' wrapper and log processor. Your config directory is "/Users/felix/Library/Preferences/rogcat".

USAGE:
    rogcat [FLAGS] [OPTIONS] [COMMAND] [SUBCOMMAND]

FLAGS:
    -d, --dump              Dump the log and then exit (don't block)
        --help              Prints help information
        --hide-timestamp    Hide timestamp in terminal output
        --no-dimm           Use white as dimm color
        --overwrite         Overwrite output file if present
        --restart           Restart command on exit
        --show-date         Show month and day in terminal output
    -s, --skip              Skip records on a command restart until the last received last record is received again. Use
                            with caution!
    -V, --version           Prints version information

OPTIONS:
    -b, --buffer <buffer>...
            Select specific logd buffers. Defaults to main, events, kernel and crash

        --color <color>                          Terminal coloring option [possible values: auto, always, never]
    -a, --filename-format <filename_format>
            Select a format for output file names. By passing 'single' the filename provided with the '-o' option is
            used (default).'enumerate' appends a file sequence number after the filename passed with '-o' option
            whenever a new file is created (see 'records-per-file' option). 'date' will prefix the output filename with
            the current local date when a new file is created [possible values: single, enumerate, date]
    -f, --format <format>
            Output format. Defaults to human on stdout and raw on file output [possible values: csv, html, human, json,
            raw]
    -H, --head <head>                            Read n records and exit
    -h, --highlight <highlight>...
            Highlight messages that match this pattern in RE2. The prefix '!' inverts the match

    -i, --input <input>...
            Read from file instead of command. Use 'serial://COM0@115200,8N1 or similiar for reading a serial port

    -l, --level <level>
            Minimum level [possible values: trace, debug, info, warn, error, fatal, assert, T, D, I, W, E, F, A]

    -m, --message <message>...                   Message filters in RE2. The prefix '!' inverts the match
    -M, --Message <message-ignore-case>...       Same as -m/--message but case insensitive
    -o, --output <output>                        Write output to file
    -p, --profile <profile>                      Select profile
    -P, --profiles-path <profiles_path>          Manually specify profile file (overrules ROGCAT_PROFILES)
    -n, --records-per-file <records_per_file>    Write n records per file. Use k, M, G suffixes or a plain number
    -r, --regex <regex_filter>...                Regex filter on tag, pid, thread and message.
    -t, --tag <tag>...                           Tag filters in RE2. The prefix '!' inverts the match
    -T, --Tag <tag-ignore-case>...               Same as -t/--tag but case insensitive
        --tail <tail>                            Dump only the most recent <COUNT> lines (implies --dump)

ARGS:
    <COMMAND>    Optional command to run and capture stdout and stdderr from. Pass "-" to d capture stdin'. If
                 omitted, rogcat will run "adb logcat -b all" and restarts this commmand if 'adb' terminates

SUBCOMMANDS:
    bugreport      Capture bugreport. This is only works for Android versions < 7.
    clear          Clear logd buffers
    completions    Generates completion scripts
    devices        List available devices
    help           Prints this message or the help of the given subcommand(s)
    log            Add log message(s) log buffer

Licensing

See LICENSE for details.

rogcat's People

Contributors

flxo avatar ir210 avatar jimmydurandwesolowski avatar miklelappo avatar mortronmeymo avatar pftbest avatar sebs2837 avatar sgasse avatar sirius-cc-wu avatar stebalien avatar wngr avatar zachariaszeiler avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

rogcat's Issues

Cut a new release

Hey,

thanks for your project, it's a nice little helper in my daily workflow :-).

Given that there are a few things since the last release to crates.io (from May '19) โ€“ especially exposing the parser in lib โ€“ it would be great if you could cut a new release and make it more accessible like that.

Thanks!

`rogcat profiles --list` does not list profiles on rogcat 0.4.5

I'm running into trouble loading rogcat profiles (and subsequently using them via -p flag) on 0.4.5. I have not rolled back to see if this is a regression.

Details below:

$ rogcat --version
rogcat 0.4.5

# Contents of profiiles.toml.
$ cat $HOME/Library/Preferences/rogcat/profiles.toml
[profile.a]
comment = "Messages starting with A or a"
message_ignore_case = ["^A.*"]

[profile.B]
comment = "Messages starting with B"
message = ["^B.*"]

[profile.ABC]
extends = ["A", "B"]
comment = "Profiles A, B plus the following filter (^C.*)"
message = ["^C.*"]

[profile.default]
comment = "Default profile"

# Try to list profiles
$ rogcat profiles --list
error: Found argument '--list' which wasn't expected, or isn't valid in this context

USAGE:
    rogcat [FLAGS] [OPTIONS] [COMMAND] [SUBCOMMAND]

For more information try --help

# Try again without --
$ rogcat profiles list
error: Found argument 'list' which wasn't expected, or isn't valid in this context

USAGE:
    rogcat [FLAGS] [OPTIONS] [COMMAND] [SUBCOMMAND]

For more information try --help

# Check Env Var
$ echo $ROGCAT_PROFILES

# Set Env Var + Retry
$ ROGCAT_PROFILES=$HOME/Library/Preferences/rogcat/profiles.toml rogcat profiles --list
error: Found argument '--list' which wasn't expected, or isn't valid in this context

USAGE:
    rogcat [FLAGS] [OPTIONS] [COMMAND] [SUBCOMMAND]

For more information try --help

$ ROGCAT_PROFILES=$HOME/Library/Preferences/rogcat/profiles.toml rogcat profiles list
error: Found argument 'list' which wasn't expected, or isn't valid in this context

USAGE:
    rogcat [FLAGS] [OPTIONS] [COMMAND] [SUBCOMMAND]

For more information try --help

If /dev/log/all does not exist on the device the app fails and keeps printing "Restarting..."

My device is running Android 4.0.3 and it doesn't contain the /dev/log/all file, so I get the following error if I run 'rogcat.exe' over and over

Restarting "C:\Users\abid.esmail\AppData\Local\Android\sdk\platform-tools\adb.exe logcat -b all"
() - Unable to open log device '/dev/log/all': No such file or directory
Restarting "C:\Users\abid.esmail\AppData\Local\Android\sdk\platform-tools\adb.exe logcat -b all"
() - Unable to open log device '/dev/log/all': No such file or directory

shell@android:/dev/log $ ll
crw-rw--w- root log 10, 55 2014-01-31 17:00 events
crw-rw--w- root log 10, 56 2014-01-31 17:00 main
crw-rw--w- root log 10, 54 2014-01-31 17:00 radio
crw-rw--w- root log 10, 53 2014-01-31 17:00 system

Thanks,
Abid

Add command line switch to select adb device

I have a workstation where multiple android devices are connected via USB. When running rogcat it get...

                                                 ()  -    - waiting for device -
                                                 ()  -    error: more than one device/emulator

so basically the same as I would get from adb logcat. Could you add a command line switch to select the device by the serial number? Similar to adb's -s switch?

Crash loop with more than one device

( )  -    error: more than one device/emulator
( )  -    - waiting for device -
( )  -    error: more than one device/emulator
( )  -    - waiting for device -
....

^ That's what I get when I start rogcat and have two androids with USB debugging enabled

Edit: I installed through brew and have version 0.2.15

Reading file fails

Hi,
there is a issue if i wahnt to read a stored file into rogcat. The issue is on different locations, also it is no effect if I try to import a logcat log or a before stored rogcat log. I get always the message:

Failed to open rogcat.log: blocking annotated I/O must be called from the context of the Tokio runtime.

No effect are also if I use the complete pathname or run it from the directory, where the file is located.
Version is: 0.4.3

Issue is not in 0.4.1 existing

Failed to lock terminal

Hi,

After a recent Linux system upgrade I'm getting the following error (from src/terminal.rs:82) when I execute rogcat:

Failed to lock terminal

I'm getting the same error even uninstalling and re-installing rogcat using cargo.

adb logcat on the other hand works properly

Some extra info:

Linux x1 4.14.27-1-MANJARO #1 SMP PREEMPT Thu Mar 15 19:47:13 UTC 2018 x86_64 GNU/Linux
cargo 1.26.0-nightly (5f83bb404 2018-03-09)
rustc 1.26.0-nightly (55c984ee5 2018-03-16)

Question about features and support formats

Great Tool with some awesome features.

Can rogcat parse an existing adb logcat file? We get logcat files from the field and would like to parse them into an easily readable format.

So can it parse a file that is outputted from the command adb logcat -v threadtime > adblogs.txt

If this tool cannot do this, do you have any suggestions of other tools that can do this.

Thanks,
Abid

Multiple devices

Sorry if this is by chance really obvious, I know there's rogcat devices to list the available devices.
Is there an option to use the ANDROID_SERIAL to switch between devices, similar to adb -s option?

rogcat as a library

Hi. Is rogcat a wrapper over logcat binary or is it a port with more features? I want to write a log shipper for android. My service runs inside android and I need a way to read logs. Can rogcat be used for this purpose?

Reader implementations block event loop

The reader::* Stream implementation may block. This should be refactored to use the tokio-io stuff and probably a additional thread that feeds a channel.

Build failed: No such file or directory (os error 2), src/libcore/result.rs:997:5

I build the project on Ubuntu 18.04. I installed Rust by running

curl https://sh.rustup.rs -sSf | sh

then run

RUST_BACKTRACE=1 cargo install --path .

I get this error

  Installing rogcat v0.3.1-alpha.0 (/home/gqqnbig/Project/rogcat)
   Compiling libudev-sys v0.1.4
   Compiling tokio-current-thread v0.1.4
   Compiling idna v0.1.5
   Compiling parking_lot_core v0.3.1
   Compiling rand_chacha v0.1.0
   Compiling rand_pcg v0.1.1
   Compiling rand v0.6.1
   Compiling rand v0.5.5
error: failed to run custom build command for `libudev-sys v0.1.4`
process didn't exit successfully: `/home/gqqnbig/Project/rogcat/target/release/build/libudev-sys-364e8e627474c66d/build-script-build` (exit code: 101)
--- stderr
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: "Failed to run `\"pkg-config\" \"--libs\" \"--cflags\" \"libudev\"`: No such file or directory (os error 2)"', src/libcore/result.rs:997:5
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:39
   1: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:70
   2: std::panicking::default_hook::{{closure}}
             at src/libstd/sys_common/backtrace.rs:58
             at src/libstd/panicking.rs:200
   3: std::panicking::default_hook
             at src/libstd/panicking.rs:215
   4: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:478
   5: std::panicking::continue_panic_fmt
             at src/libstd/panicking.rs:385
   6: rust_begin_unwind
             at src/libstd/panicking.rs:312
   7: core::panicking::panic_fmt
             at src/libcore/panicking.rs:85
   8: core::result::unwrap_failed
   9: build_script_build::main
  10: std::rt::lang_start::{{closure}}
  11: std::panicking::try::do_call
             at src/libstd/rt.rs:49
             at src/libstd/panicking.rs:297
  12: __rust_maybe_catch_panic
             at src/libpanic_unwind/lib.rs:87
  13: std::rt::lang_start_internal
             at src/libstd/panicking.rs:276
             at src/libstd/panic.rs:388
             at src/libstd/rt.rs:48
  14: main
  15: __libc_start_main
  16: _start

warning: build failed, waiting for other jobs to finish...
error: failed to compile `rogcat v0.3.1-alpha.0 (/home/gqqnbig/Project/rogcat)`, intermediate artifacts can be found at `/home/gqqnbig/Project/rogcat/target`

Caused by:
  build failed

How do I build it properly?

toml vs xml profiles file

Hi,

Thanks for the tool!

I guess that rogcat profiles --list subcommand expects an profiles.xml in the config dir, however in the README you recommend to create a profiles.toml. Indeed if you create a toml file you will get the following error when issuing rogcat profiles --list

No profiles present in "/home/username/.config/rogcat/profiles.xml"

Maybe you can change the profiles subcommand such that it parses (only) toml files?

Missing Package Requirement for Ubuntu 20.04

Following error has been observed :

error: failed to run custom build command for libudev-sys v0.1.4
Caused by:
process didn't exit successfully: rogcat/target/release/build/libudev-sys-081b531eee85ba8b/build-script-build (exit status: 101)

The reason is that package libudev-dev needs to be installed.

Command :

sudo apt-get install libudev-dev

(Feature Request) Allow running commands without the "adb" prefix

Hi! thanks for this, its amazing!
I use this on my laptop but considering that logcat is built into Android phones and doesnt need adb it would be great if we could run the commands without adb prefixed to them.
Reasons?

  • A PC isnt needed for a logcat, so it shouldnt be a requirement .
  • I use Termux on my tablet when I'm away from home (away from a PC), it would be great continue using this in those situations.
  • Rooted devices (like mine) and older devices (before android 7) actually have adb binaries, let us use them too!

I can build this but when issuing "rogcat" I get "cannot find binary path", as stated, I have adb & fastboot
on my device, so my guess is that rogcat is looking for the binaries only /usr/bin but Android binaries are in /system/bin & /system/xbin.
If you do not oppose to the idea, then my guess is that all it would take is a check (uname) to get device type and then rogcat would either prefix the commands with adb first or not, or which adb would locate the binary, or simply allow a variable in rogcats config.yml that would decide instead.

Again, thank you!

Rogcat can't parse log messages in the morning until 10

After experimenting a bit:

First variant doesn't work (7:21:49), second does (07:21:49). Both seem to be valid timestamps.

โžœ echo "2021-09-24 7:21:49.410 4249 140276332086464 D Test: test" | rogcat -
() - 2021-09-24 7:21:49.410 4249 140276332086464 D Test: test
โžœ echo "2021-09-24 07:21:49.410 4249 140276332086464 D Test: test" | rogcat -
07:21:49.410 Test (4249 140276332086464) D test

bug: Rogcat fails to start with stdin parameter

{code}
./target/debug/rogcat -
thread 'thread 'tokio-runtime-worker-0tokio-runtime-worker-1' panicked at '' panicked at 'attempted to leave type internal::Local uninitialized, which is invalidattempted to leave type internal::Local uninitialized, which is invalid', ', /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/core/src/mem/mod.rs/rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/core/src/mem/mod.rs::663663::99
{code}

This is a problem with Crossbeam 0.7.1. Update to 0.7.2 will help.
It's discussed here: darakian/ddh#27

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.