• Stars
    star
    562
  • Rank 79,281 (Top 2 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created over 12 years ago
  • Updated almost 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A colorful and highly configurable alternative to the standard "adb logcat" command from the Android SDK

logcat-color

A colorful and highly configurable alternative to the adb logcat command from the Android SDK.

Note: logcat-color is targetted at OS X and Linux, and does not currently work in Windows.

Installation

Installation with pip / easy_install (may require sudo)

$ [sudo] pip install logcat-color

.. or ..

$ [sudo] easy_install logcat-color

Installation from source (requires setuptools, may require sudo)

To get the source, simply download and extract a release tarball. Alternatively, you can clone the logcat-color git repository directly:

$ git clone git://github.com/marshall/logcat-color.git

To install logcat-color from the source directory, run:

$ python setup.py install

Examples

Run and colorify adb logcat

$ logcat-color

Colorify an old logcat text file you have laying around

$ logcat-color < /path/to/my.log

Pipe logcat-color to egrep for only the tags you care about

$ logcat-color -e | egrep '(Tag1|Tag2)'

Run logcat-color with a custom profile for filters, colors, and custom arguments)

$ logcat-color <profile-name>

logcat-color also supports most of the standard adb / logcat arguments, making it a suitable full-time replacement for adb logcat

$ alias logcat=/path/to/logcat-color
$ logcat -e
$ logcat -d
$ logcat -s 123456789 -b radio -b main

For command line usage documentation:

$ logcat-color --help

Configuration

logcat-color supports a configuration file at $HOME/.logcat-color

The configuration file is simply a python script, with a few interesting variables and types available to it.

Sample .logcat-color

# Full path to adb, default is to look at the environment variable ADB, or
# fall back on using "adb" from the system PATH
adb = "/path/to/adb"

# Width of the TAG column, default is 20
tag_width = 20

# Width of the PID column, default is 8
pid_width = 8

# Width of priority (log level) column, default is 3
priority_width = 3

# Whether or not to wrap the message inside a column. Setting this to False
# enables easier copy/paste. default is True
wrap = True

Profiles

Profiles live in the logcat-color configuration file, and allow logcat-color to customize ADB and logging even further.

In short, a single Profile can:

  • Filter based on arbitrary log data.
  • Use custom adb command line arguments, devices, and log formats
  • Customize display and color configuration.

A profile is created by simply calling the Profile python constructor with various named arguments. The only required argument is the Profile's name:

Profile(name = "myProfile", ...)

You can then have logcat-color use this profile by providing it on the command line. For example:

$ logcat-color myProfile

To customize the Profile, simply pass more named arguments to the Profile constructor. This is a list of all the currently supported named arguments:

  • buffers: A list of logcat buffers to display. By default logcat uses only the main system buffer. See the Android documentation for logcat buffers for more information.
  • device: Specifies the device this profile is intended for. Valid values: True (connect to first available device), or a string with the serial ID of the device as reported by adb devices
  • emulator: Similar to device, but providing True connects to the first available emulator instead.
  • filters: A list or tuple of custom filters.
  • format: The logcat format to use. By default logcat uses the brief format. See the Android documentation for logcat formats for more information.
  • name: The profile name (required).
  • priorities: A list or tuple of priority levels. logcat-color will exclude any messages that contain priorities not in this list. Valid priorities: V (verbose), D (debug), I (info), W (warn), E (error), F (fatal).
  • tags: A list, tuple, or dict of logcat tag names. logcat-color will exclude any messages that contain tags not in this list. When a dict is used, you can also assign custom colors to each tag. Valid tag colors: RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE
  • wrap: Whether or not to wrap the message column. Default is True.
  • packages: An array containing the packages that you want to filter on. this will be applied in addition to the filters.

Here is an extended example:

Profile(name = "radio",
    # Specify a custom device
    device = "device_name",

    # Enable both radio and main buffers (-b radio -b main)
    buffers = ("radio", "main"),

    # Only pay attention to the RIL and RILC tags, and give them custom colors
    tags = {
        "RIL": BLUE,
        "RILC": GREEN
    },

    # Only look at these priority levels
    priorities = ("I", "W", "E"),

    # Use threadtime format to get date/time stamps and thread IDs
    format = "threadtime",

    # Some custom filters
    filters = (
      r"My Custom Regex",
      lambda data: data["message"] == "Custom filter"
    ),
)

Filters

Filters allow your profile to have complete control over what log data you actually see when you run logcat-color.

logcat-color will run each line of log output through the list of filters in your profile. Only when the entire list of filters have accepted the line will it actually be displayed. This is the equivalent of logically ANDing the results of each filter. If you require different logic, you should use a custom function filter, and combine the results of various filters manually.

There are currently two different kinds of filters:

Regex filters

When the regex matches the message portion of a line of logcat output, that line will then be matched against the next filter. For example:

# A negated regex -- exclude any line that matches this
def negatedRegex(regex):
  return r"^(?!.*" + regex + ").*$"

Profile(...
  filters = (negatedRegex(r"debugging: "), r"my custom regex")
)

Function filters

When the function returns True for a line of log output, that line will then be matched against the next filter. The function will be passed a data dictionary that contains all of the log data:

  • "priority": One of the logcat priorities: V (verbose), D (debug), I (info), W (warn), E (error), F (fatal). Availability: All logcat formats.
  • "message": The log message itself Availability: All logcat formats.
  • "tag": The Tag of this log message. Availability: All logcat formats except thread.
  • "pid": The PID of the process that logged the message (in string form). Availability: All logcat formats except tag.
  • "tid": The ID of the thread that logged the message (in string form). Availability: thread, threadtime, and long formats.
  • "date": The date of the log message (in string form). Availability: time, threadtime, and long formats.
  • "time": The time of the log message (in string form). Availability: time, threadtime, and long formats.

Notice that many of these fields are conditional based on the logcat output format. Be careful when constructing the logic of function filters, as the field you are filtering may not exist in the message!

An example of a function filter:

# only include messages from my app's tags
def onlyMyApp(data):
    # Tag isn't available in "thread" format, so use get() to be safe and
    # return None instead of raising an exception
    return data.get("tag") in ("MyAppTag1", "MyAppTag2")

Profile(...
    filters = (onlyMyApp)
)

Package Filters

When you only care about a few (or one) application this will pass all messages to you by that application.

Note: This will require the application's startup message to be accessible via the current logback trace. The best bet it to start logcat-color then start the app.

An example of package filters

Profile(...
    packages = [ "com.android.example" ]
)

Screenshot

logcat-color screenshot of Boot2Gecko

Thanks

Thanks to Jeff Sharkey for the original script that logcat-color is based on, coloredlogcat.py.

More Repositories

1

titanium

This repository has relocated to http://github.com/appcelerator/titanium_desktop
JavaScript
174
star
2

dotfiles

nearly two decades worth of accrued configuration for various tools
Shell
11
star
3

webkit_titanium

This repository has moved to http://github.com/appcelerator/webkit_titanium
JavaScript
9
star
4

titanium_build

Build scripts and config for Titanium and it's branches
Python
9
star
5

titanium_sqlite_demo

Use an existing sqlite DB in a Titanium Desktop app
8
star
6

github

A command line interface for github
6
star
7

quicksnap

A quick desktop snapshot taker and cropper written with Titanium and Ruby
Ruby
6
star
8

PyCSP

python bindings for the Cubesat Space Protocol
Python
5
star
9

titanium_php_mysql_demo

A demo showing connect / querying a public MySQL server w/ Titanium
5
star
10

qemu

playing with arduino due emulation in qemu
C
4
star
11

zephyr-docker

Zephyr Project Docker Image
3
star
12

screengrabber

a screenshot grabber written in Titanium
JavaScript
3
star
13

pynaries

a simple python-based dependency resolution system
Python
3
star
14

mintest

A minimal C unit testing framework targetted at embedded systems
C
3
star
15

retry

Continually run any command until it succeeds (or fails!)
Rust
2
star
16

deltafy

Scan for the deltas in your file tree with python
Python
2
star
17

titanium_transparency_demo

Showing off Dithered / custom shaped windows in Titanium 0.8.1
2
star
18

titanium_tools

Developer Tools for Titanium SDK
Java
2
star
19

github_markdown_preview

A node.js / command line preview script for Github style Markdown
JavaScript
2
star
20

marshall.github.com

1
star
21

rhino_titanium

Java
1
star
22

vertbalance

A multi-platform balance checker for Vertcoin
JavaScript
1
star
23

node-optimist

Light-weight option parsing for node.js
JavaScript
1
star
24

titanium_json_benchmark

A quick benchmark showing the speed increases WebKit's native JSON parser has to offer
JavaScript
1
star
25

brave-versions

Generate an easily queryable metadata set about Brave releases
JavaScript
1
star