• Stars
    star
    203
  • Rank 192,890 (Top 4 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created about 7 years ago
  • Updated 9 months ago

Reviews

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

Repository Details

The powerful log analysis, you can use it to parse any log.

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

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['

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

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.

More Repositories

1

JKeyboardPanelSwitch

For resolve the layout conflict when keybord & panel are switching (Android键盘面板冲突 布局闪动处理方案)
Java
4,182
star
2

filedownloader-okhttp3-connection

The FileDownloadConnection implemented with the okhttp3
Java
117
star
3

webp-converter

Converter PNG/JPG to Webp and scan all changes
Python
108
star
4

ThreadDebugger

Threads monitor and the thread pool factory.
Java
85
star
5

grpc-android-kotlin

Simple grpc Server/Android written in kotlin, protobuf generated java files
Kotlin
50
star
6

android-project-combine

combine multiple android gradle projects on one Android Studio window.
Python
32
star
7

Android_CACHE_MANAGER

Android文件&缓存管理
29
star
8

MessageHandler

Simple Handler forwarding, for supporting pause、resume、cancelAllMessage、killSelf skills.
Java
28
star
9

wuhan-2019-nCoV

武汉2019nCov信息爬虫
Python
23
star
10

crash-pvp

To Crash the King of Glory(王者荣耀) when you launch it
Java
22
star
11

Blog

知识, 学习、沉淀与分享
Stylus
20
star
12

gralde-sample

Some demonstrate for gradle.
Java
17
star
13

PercentSmoothHandler

Handle the case of the internal of the percent between the current and the last is too large to smooth for the target progress widget or event others
Java
17
star
14

Magnifier_Word

长按英语单词放大镜取词,取到单词后toast结果。
Java
16
star
15

wechat-backup-merge

Merge and migrate Wechat backup files to another folder
Python
15
star
16

wechat-hunter

the hunter for wechat based on Xposed
Java
12
star
17

notification-adapter

The adapter for notification, what is used for adapter various system styles on notification
Java
7
star
18

COCOS2D-X_LINKGAME

基于Cocos2d-x连连看游戏
C++
7
star
19

SOCKET_HANLE

Android有关Socket逻辑处理(心跳、断线重连、发送、接收、alarm省点处理).
5
star
20

AIDL_COMMUNICATE-CALLBACK

AIDL_COMMUNICATE-CALLBACK
Java
5
star
21

Android-Touch-Gallery

Android touch gallery with net、local file or cache.
Java
2
star
22

FlatBuffer-Optimize

flatbuffer optimize
Python
2
star
23

Android_Poll

自实现轮询&消息管理
1
star
24

workflows-proxy

switch Tencent proxy and Home Proxy
Python
1
star
25

server-maintain

自动化生成各类Ubuntu下的站点环境的Bash脚本
Shell
1
star
26

Android-Database-Construct

Android Database Construct
Java
1
star