Code Monkey home page Code Monkey logo

okcat's Introduction

OkCat

Build Status

An powerful log processor.

中文文档

  • The adb logcat handler is just update to JakeWharton's nice pidcat and I adapt it for more features.
  • You can using this log processor with define you own log-line-regex and it can work for any log: iOS, Android, Backend, etc.

Features

The most important feature is you can define any regex for any kind of log.

  • highlight some keywords
  • trans msgs to some words
  • trans tags to some words
  • hide msg on logs
  • separate logs
  • ignore msg on logs: when you provide such list, the msg start with provided msg will be ignored to printed
  • ignore tag on logs: when you provide such list, the tag in the list will be ignored to printed

How to Install

sudo pip install okcat

If you has not installed pip yet, you need to install it first:

  1. brew install python
  2. sudo easy_install pip

If you want to upgrade:

sudo pip install okcat --upgrade

How to Use


Simplest test

  1. Download: download filedownloader.yml to the current folder or move to the ~/.okcat/ folder
  2. Running: run the demo project on Filedownloader repo to your Android phone and connect your Phone to computer
  3. Execute: okcat -y=filedownloader
  4. Done: now, you can checkout the colored logs on terminal, enjoy~


1. Define your config file(.yml)

You can create your own .yaml file as config file on ~/.okcat/ folder or the current folder you will execute okcat command, and the filename is free to choose, when you execute the okcat, we will ask you the configure file name you want to apply.

the following is demo of config file, Of course, you don't have to provide all configs such below, if you think which one is needed, just config that one.

# extends from exist yml file (provide only filename without `.yml` extension)
# from: exist-yml-name

# we will filter out logs with the provided package (name)
# this 'package' keyword is just using for android adb logcat
package: com.liulishuo.filedownloader.demo

# this 'log-line-regex' is just a regex for one line log
# now we support keyword: 'date' 'time' 'level' 'tag' 'process' 'thread' 'message'
# you don't have to provide all keyword, but you have to provide at least the 'message'
# such as: 'message="(\S*)"'
log-line-regex: 'date,time,process,thread,level,tag,message = "(.\S*) *(.\S*) *(\d*) *(\d*) *([A-Z]) *([^:]*): *(.*?)$"'

# on the case of filter logs from Android adb logcat, we using 'adb logcat -v brief -v threadtime' command to obtain logcat
# in the normal case you don't need ot provide this config, because there is a perfect one on the okcat internal
# but if you want to customize the regex log from adb logcat, it's free to define it such below
# adb-log-line-regex: 'date,time,process,thread,level,tag,message="(.\S*) *(.\S*) *(\d*) *(\d*) *([A-Z]) *([^:]*): *(.*?)$"'

# separator regex list
# you can provide multiple regex to separate serial logs
separator-regex-list:
  # on this case, if one line log match 'call start Url\[([^\]]*)\]' regex we will separate logs with \n and output a indie line with the '([^\]]*)' value as the title of separate
  - 'call start Url\[([^\]]*)\]'

# tag keyword list
# this list keyword is using for filter out which log need to be output
# all provided keyword will be using for compare with each line tag, if a line with tag not contain any keyword on 'tag-keyword-list' it will be ignore to output
tag-keyword-list:
  - 'FileDownloader'

# translate message map
# if a message on a line start with provide keyword on the 'trans-msg-map' we will add the value of the keyword on the start of the message, and the word of value will be colored to highlight it
trans-msg-map:
  # such as this case:
  # origin message: 'filedownloader:lifecycle:over xxx'
  # after translate: '| Task OVER | filedownloader:lifecycle:over xxx'
  'filedownloader:lifecycle:over': 'Task OVER'
  'fetch data with': 'Start Fetch'

# translate tag map
# if a tag on a line contain provide keyword on the 'trans-tag-map' we will add the value of the keyword on the start of the message, and the background of the value word will be colored to highlight it
trans-tag-map:
  # such as this case:
  # origin message: 'FileDownloader.DownloadTaskHunter  xxx'
  # after translate: 'FileDownloader.DownloadTaskHunter [Status Change] xxx'
  'DownloadTaskHunter': '[Status Change]'
  'ConnectTask': '[Request]'

# hide message list
# if a message on a line start with provide value on the 'hide-msg-list` and the length of the message is less than 100 word, it would be colored with gray to hide
hide-msg-list:
  # here we hide message start with 'notify progress' and '~~~callback' because it is too frequently to output and useless in most case
  - 'notify progress'
  - '~~~callback'

# highlight list
# if any value on the 'highlight-list' display on any message, the background of the value word would be colored to highlight it
highlight-list:
  - 'Path['
  - 'Url['
  - 'Tag['
  - 'range['

# ignore message list
# when you provide such list, the msg start with provided msg will be ignored to printed 
ignore-msg-list:
  - 'log start with this will be ignored' 

# ignore tag list
# when you provide such list, the tag in the list will be ignored to printed
ignore-tag-list:
  - 'tagToBeIgnored'

2. Execute

You can just parse logcat from running adb:

okcat -y=your-conf-name

You also can parse your log file through:

okcat -y=your-conf-name your-log-path1 your-log-path2 your-log-path3 ... 

Simplest case for any developer:

okcat your.package.name

Tips: You can use command + k on Terminal to flush all content on the session and start a new okcat parse instead of creating anthor new session.

My Terminal Config

If you want to adapter the same theme like screenshot above, it's very easy:

  • Firstly, please use powerlevel9k theme(Install the Powerlevel9k Theme and Powerline Fonts as the powerlevel9k repo readme doc said).
  • Secondly, please config the iTerm2-Neutron color scheme.
  • Thirdly, please config your shell(If you are using zsh, just add following code to the ~/.zshrc file):
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir vcs)
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status time)
POWERLEVEL9K_TIME_FORMAT="%D{%H:%M:%S}"
POWERLEVEL9K_NODE_VERSION_BACKGROUND='022'
POWERLEVEL9K_SHORTEN_DIR_LENGTH=2

Dev

Import to PyCharm, and Set the Project Structure:

LICENSE

Copyright (C) 2017 Jacksgong(jacksgong.com)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

okcat's People

Contributors

jacksgong avatar lazycountry avatar oksep 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

okcat's Issues

没有任何输出啊

输出如下:

okcat -y=filedownloader <path to log>
-------------------------------------------------------
                  OkCat v1.3.0

Thanks for using okcat! Now, the doc is available on:
        https://github.com/Jacksgong/okcat

                   Have Fun!
-------------------------------------------------------
using config on /Users/xxx/tools/okcat/filedownloader.yml
find regex: ['date', 'time', 'level', 'tag', 'process', 'thread', 'message'] with (.\S*) *(.\S*) *(\d*) *(\d*) *([A-Z]) *([^:]*): *(.*?)$

用 adb 连上设备后, 也没有任何输出

»okcat -y=filedownloader                                                                                                         
-------------------------------------------------------
                  OkCat v1.3.0

Thanks for using okcat! Now, the doc is available on:
        https://github.com/Jacksgong/okcat

                   Have Fun!
-------------------------------------------------------
using config on /Users/xxx/tools/okcat/filedownloader.yml
find regex: ['date', 'time', 'process', 'thread', 'level', 'tag', 'message'] with (.\S*) *(.\S*) *(\d*) *(\d*) *([A-Z]) *([^:]*): *(.*?)$
^CADB CONNECTION IS LOST.

系统: mac os

Can I install OkCat under windows ?

Just install it under win7 by:
pip install okcat

But got some encoding error:
Collecting okcat
Using cached OkCat-1.1.1.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\xxxx\AppData\Local\Temp\pip-build-7butabya\okcat\setup.py", line 23, in
long_description = f.read()
UnicodeDecodeError: 'cp950' codec can't decode byte 0x96 in position 438: illegal multibyte sequence

adb connection is lost

device & adb is connected

when I execute cmd okcat -y darwin.yml , I got

using config on /Users/sep/.okcat/darwin.yml
using config on /Users/sep/.okcat/logx.yml
find regex: ['data', 'time', 'process', 'thread', 'level', 'tag', 'message'] with (.\S*) *(.\S*) *(\d*) *(\d*) *([A-Z]) *([^:]*): *(.*?)$
ADB CONNECTION IS LOST.

How to resolve this issue, tks

运行okcat 包名 会出现以下错误 是怎么回事呢?

Traceback (most recent call last): File "/usr/local/bin/okcat", line 9, in <module> load_entry_point('OkCat==1.1.3', 'console_scripts', 'okcat')() File "/Library/Python/2.7/site-packages/okcat/__init__.py", line 102, in main _adb.setup(args) File "/Library/Python/2.7/site-packages/okcat/adb.py", line 166, in setup self.adb = subprocess.Popen(adb_command, stdin=PIPE, stdout=PIPE) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 710, in __init__ errread, errwrite) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1335, in _execute_child raise child_exception OSError: [Errno 2] No such file or directory

用不了啊

Traceback (most recent call last):
File "/usr/local/bin/okcat", line 11, in
load_entry_point('OkCat==1.0.9', 'console_scripts', 'okcat')()
File "/usr/lib/python3/dist-packages/pkg_resources/init.py", line 561, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python3/dist-packages/pkg_resources/init.py", line 2631, in load_entry_point
return ep.load()
File "/usr/lib/python3/dist-packages/pkg_resources/init.py", line 2291, in load
return self.resolve()

Traceback (most recent call last)

报错信息:

Traceback (most recent call last):
File "/Users/xiaoyee/.pyenv/versions/3.5.0/bin/okcat", line 9, in
load_entry_point('OkCat==1.0.8', 'console_scripts', 'okcat')()
File "/Users/xiaoyee/.pyenv/versions/3.5.0/lib/python3.5/site-packages/pkg_resources/init.py", line 558, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/Users/xiaoyee/.pyenv/versions/3.5.0/lib/python3.5/site-packages/pkg_resources/init.py", line 2682, in load_entry_point
return ep.load()
File "/Users/xiaoyee/.pyenv/versions/3.5.0/lib/python3.5/site-packages/pkg_resources/init.py", line 2355, in load
return self.resolve()
File "/Users/xiaoyee/.pyenv/versions/3.5.0/lib/python3.5/site-packages/pkg_resources/init.py", line 2361, in resolve
module = import(self.module_name, fromlist=['name'], level=0)
File "/Users/xiaoyee/.pyenv/versions/3.5.0/lib/python3.5/site-packages/okcat/init.py", line 35
print ""
^
SyntaxError: Missing parentheses in call to 'print'

如下图:

image

cus.yml
只修改了 package
package: com.sothree.slidinguppanel.demo`

电脑信息:
image
shou'j
手机信息:
Nexus 5x-Andriod8.0.0
HTC 802w-Andriod5.0.2

windows error: KeyError: 'HOME'

PS C:\Users\Administrator.okcat> okcat.exe -y=demo-config.yml demo-log-file.log
Traceback (most recent call last):
File "c:\users\administrator\appdata\local\programs\python\python37\lib\runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "c:\users\administrator\appdata\local\programs\python\python37\lib\runpy.py", line 85, in run_code
exec(code, run_globals)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\Scripts\okcat.exe_main
.py", line 5, in <module

File "c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages\okcat_init_.py", line 21, in

from okcat.adb import Adb
File "c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages\okcat\adb.py", line 20, in
from okcat.confloader import ConfLoader
File "c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages\okcat\confloader.py", line 22, i
n
from okcat.helper import handle_home_case, get_conf_path
File "c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages\okcat\helper.py", line 31, in
HOME_PATH = environ['HOME']
File "c:\users\administrator\appdata\local\programs\python\python37\lib\os.py", line 678, in getitem
raise KeyError(key) from None
KeyError: 'HOME'
PS C:\Users\Administrator.okcat>

error occur while running in windows 7 OS .Please help to check. 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.