GithubHelp home page GithubHelp logo

marshall / logcat-color Goto Github PK

View Code? Open in Web Editor NEW
560.0 33.0 62.0 406 KB

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

License: Apache License 2.0

Python 100.00%

logcat-color's Introduction

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.

logcat-color's People

Contributors

coi-l avatar ethankhall avatar johnjohndoe avatar marshall avatar mykmelez 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  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

logcat-color's Issues

Install fails on Ubuntu 15.04

mac@mac-desktop:$ sudo git clone git://github.com/marshall/logcat-color.git
Cloning into 'logcat-color'...
remote: Counting objects: 309, done.
remote: Total 309 (delta 0), reused 0 (delta 0), pack-reused 309
Receiving objects: 100% (309/309), 410.58 KiB | 507.00 KiB/s, done.
Resolving deltas: 100% (130/130), done.
Checking connectivity... done.
mac@mac-desktop:
$ cd logcat-color
mac@mac-desktop:/logcat-color$ ls -al
total 80
drwxr-xr-x 5 root root 4096 Apr 22 09:41 .
drwxr-xr-x 47 mac mac 4096 Apr 22 09:41 ..
drwxr-xr-x 8 root root 4096 Apr 22 09:41 .git
-rw-r--r-- 1 root root 22 Apr 22 09:41 .gitignore
-rw-r--r-- 1 root root 11359 Apr 22 09:41 LICENSE
drwxr-xr-x 2 root root 4096 Apr 22 09:41 logcatcolor
-rwxr-xr-x 1 root root 10201 Apr 22 09:41 logcat-color
-rw-r--r-- 1 root root 37 Apr 22 09:41 MANIFEST.in
-rw-r--r-- 1 root root 8804 Apr 22 09:41 README.md
-rwxr-xr-x 1 root root 4529 Apr 22 09:41 release.py
-rw-r--r-- 1 root root 352 Apr 22 09:41 setup.json
-rw-r--r-- 1 root root 377 Apr 22 09:41 setup.py
drwxr-xr-x 4 root root 4096 Apr 22 09:41 test
mac@mac-desktop:
/logcat-color$ sudo python setup.py install
Traceback (most recent call last):
File "setup.py", line 5, in
from setuptools import setup, find_packages
ImportError: No module named setuptools
mac@mac-desktop:~/logcat-color$

Indentation now working

When I log something using new JSONObject(jsonString).toString(2), indentation is not shown in logcat-color output.

Trouble executing profiles

I've created a '.logcat-color' configuration file, but I'm getting a traceback when attempting to use it.
If I remove the configuration file (or comment everything out), then logcat-color works fine. I don't know where in the configuration file I'm doing something incorrect. Am I missing something in the file? I'm using the configuration example that you provided. Please help.

The error:
'
$ logcat-color
Traceback (most recent call last):
File "/usr/bin/logcat-color", line 5, in
pkg_resources.run_script('logcat-color==0.6.1', 'logcat-color')
File "/usr/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 489, in run_script
File "/usr/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 1207, in run_script
File "/usr/lib/python2.7/site-packages/logcat_color-0.6.1-py2.7.egg/EGG-INFO/scripts/logcat-color", line 252, in
LogcatColor().loop()
File "/usr/lib/python2.7/site-packages/logcat_color-0.6.1-py2.7.egg/EGG-INFO/scripts/logcat-color", line 224, in loop
self.start()
File "/usr/lib/python2.7/site-packages/logcat_color-0.6.1-py2.7.egg/EGG-INFO/scripts/logcat-color", line 218, in start
self.start_logcat()
File "/usr/lib/python2.7/site-packages/logcat_color-0.6.1-py2.7.egg/EGG-INFO/scripts/logcat-color", line 208, in start_logcat
self.input = Popen(adb_command, stdout=PIPE).stdout
File "/usr/lib/python2.7/subprocess.py", line 710, in init
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1327, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory

The .logcat-color configuration file:

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

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"
),

)

Profile(name = "CosctoApp",
packages = [ "com.costco.app.android" ]
)

Is there a way to match the tag color to the Log-type color?

For example,

The following log is an Info log with the tag DEBUG:

 97           DEBUG  I  40f83efc 0000100b 20786469 63616669 63612065  ....idx iface ac

The DEBUG tag was coloured blue here. Is there a way I can match all tag colours to their respective log-type colours?

Thanks

Support python3.5

Hi,
Thanks for this nice tool. Leaving a note here that it doesn't work on python3.5

deactivate
mkvirtualenv -p $(which python3) logcat-color
workon logcat-color
pip install logcat-color
Collecting logcat-color
  Downloading logcat-color-0.6.0.tar.gz
    Complete output from command python setup.py egg_info:
    running egg_info
    /Users/gableroux/.virtualenvs/logcat-color/lib/python3.5/site-packages/setuptools/dist.py:343: UserWarning: The version specified (b'0.6.0') is an invalid version, this may not work as expected with newer versions of setuptools, pip, and PyPI. Please see PEP 440 for more details.
      "details." % self.metadata.version
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/44/1h74hkj534j6b5cwsbkcsm200000gn/T/pip-build-5r_tbmiw/logcat-color/setup.py", line 14, in <module>
        setup(**setup_data)
      File "/usr/local/Cellar/python35/3.5.2/Frameworks/Python.framework/Versions/3.5/lib/python3.5/distutils/core.py", line 148, in setup
        dist.run_commands()
      File "/usr/local/Cellar/python35/3.5.2/Frameworks/Python.framework/Versions/3.5/lib/python3.5/distutils/dist.py", line 955, in run_commands
        self.run_command(cmd)
      File "/usr/local/Cellar/python35/3.5.2/Frameworks/Python.framework/Versions/3.5/lib/python3.5/distutils/dist.py", line 973, in run_command
        cmd_obj.ensure_finalized()
      File "/usr/local/Cellar/python35/3.5.2/Frameworks/Python.framework/Versions/3.5/lib/python3.5/distutils/cmd.py", line 107, in ensure_finalized
        self.finalize_options()
      File "/Users/gableroux/.virtualenvs/logcat-color/lib/python3.5/site-packages/setuptools/command/egg_info.py", line 172, in finalize_options
        self.egg_name = safe_name(self.distribution.get_name())
      File "/Users/gableroux/.virtualenvs/logcat-color/lib/python3.5/site-packages/pkg_resources/__init__.py", line 1378, in safe_name
        return re.sub('[^A-Za-z0-9.]+', '-', name)
      File "/Users/gableroux/.virtualenvs/logcat-color/lib/python3.5/re.py", line 182, in sub
        return _compile(pattern, flags).sub(repl, string, count)
    TypeError: cannot use a string pattern on a bytes-like object

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/44/1h74hkj534j6b5cwsbkcsm200000gn/T/pip-build-5r_tbmiw/logcat-color/
python --version
Python 3.5.2

But it works on python2.7 ๐Ÿ‘

deactivate
rmvirtualenv logcat-color
mkvirtualenv -p $(which python2.7) logcat-color
workong logcat-color
pip install logcat-color
Collecting logcat-color
  Using cached logcat-color-0.6.0.tar.gz
Collecting colorama (from logcat-color)
  Using cached colorama-0.3.7-py2.py3-none-any.whl
Building wheels for collected packages: logcat-color
  Running setup.py bdist_wheel for logcat-color ... done
  Stored in directory: /Users/gableroux/Library/Caches/pip/wheels/e0/0d/b8/8a97953450fdae828ce74af1a9072dea36b1d3a9c2da6569d2
Successfully built logcat-color
Installing collected packages: colorama, logcat-color
Successfully installed colorama-0.3.7 logcat-color-0.6.0
python --version
Python 2.7.13

Passing command line args does not always work.

Passing "-v time" option as a command line argument does not work.
There's no output at all.

Also passing "-e" option produces output:
"waiting for device"
but passing "-d" option produces normal logcat output.

cannot specity packages

I wrote
Profile(name = "test",
packages = "com.lewa.netmgr"
)
in ~/.logcat-color
and I got this error:

TypeError: init() got an unexpected keyword argument 'packages'

ImportError: No module named logcatcolor.config

On Ubuntu 12.04 I get the error:

sieguma@r9h2zfv:~$ logcat-color
Traceback (most recent call last):
File "/usr/local/bin/logcat-color", line 21, in
from logcatcolor.config import LogcatColorConfig
ImportError: No module named logcatcolor.config

I do not really find any reports on this issue - puzzled why it appears only for me?
It was installed through "pip".

Thanks,
Martin

Filtering log

In logcat, there are -e flag to filter lines of which regex pattern matching i want to see. There are none in logcat-color, but mostly what i need is removing lines containing certain strings, such as: WifiConnectivityMa.. or SupplicantWifiScan...

It would be really nice if there are such feature.

Profile does not work

from the source code of logcat-color:
if len(self.args) >= 1:
self.profile = Profile.get_profile(self.args[0])
if self.profile:
self.args = self.args[1:]
and profile.py:
class Profile(object):
profiles = {}

@classmethod
def get_profile(cls, name):
    return cls.__profiles__.get(name, None)

I found nowhere the code to load the profile

Port logcat-color to Windows

This update to Jeff Sharkey's coloredlogcat.py looks like it only works on iOS.
Adrian Vintu made some changes to Jeff's original script to make it work on Windows.

I am working on some changes and may submit them as a Pull Request if I get the following changes working correctly:

  • The "logcat-color." file isn't directly usable in Windows and needs to be renamed to logcat-color.py"
  • All uses of python libraries fcntl and termios need to be isolated
  • FileLineReader's use of asyncore.file_wrapper(fd) needs a Windows equivalent.

Maybe resorting to Jeff and Adrian's original code as a Windows impl would suffice?

File location for Profile unclear

Can you please update the documentation to specify exactly where to put the Profile information and how to call it?

I created a file in ~/.logcat-color with the following content:

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

Then I start it with $ logcat-color test but there is no output. If I omit the profile name the output can be read. I started logcat-color before starting the app.

Support all of logcat's logging formats

Logcat supports a number of output formats with the -v <format> argument. Right now, logcat-color only supports parsing the output of the brief (default) format. This would add support for the following formats:

  • process: PID only
  • tag: priority/tag only
  • raw: log messages only
  • time: time, invocation time, priority/tag, PID
  • thread: priority/tag, PID, and TID of the thread
  • threadtime: time, invocation time, priority/tag, PID, and TID of the thread
  • long: displays all fields, and separates each message with an extra line.

Profiles don't work in Android 5.1

So I updated to 5.1 and failed to get logcat-color working properly. I did no changes to the config (stored at ~/.logcat-color).

It contains

Profile(name = "billy", packages = [ "com.vibin.billy" ] )

If I just type logcat-color, it'll output the log fine, so the issue is only with profiles.
Thanks.

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.