-
-
Save rymizuki/4044208 to your computer and use it in GitHub Desktop.
Simplify android logcat.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# | |
# adb logcat をもっと見やすく. | |
# | |
require 'optparse' | |
# | |
# global option. | |
# | |
options = { | |
:loglevels => ['D'], | |
:tags => [], | |
:command => 'adb logcat -v tag', | |
:format => '[$tag]\n\t$msg', | |
:format_tag => "$tag", | |
:format_msg => "$msg", | |
:format_level => "$level", | |
:coloring => true, | |
:level_colors => { | |
'D' => 'blue', | |
'I' => 'green', | |
'W' => 'yellow', | |
'E' => 'red', | |
}, | |
:system_tags => [ | |
'AbsListView', | |
'ActivityManager', | |
'AlarmManagerService', | |
'AndroidRuntime', | |
'ApplicationPolicy', | |
'AudioHardwareALSA', | |
'AudioStreamOutALSA', | |
'AwesomePlayer', | |
'AlarmItem', | |
'AlarmWidget', | |
'AlarmReceiver', | |
'accuweather', | |
'alsa_ucm', | |
'ALSAModule', | |
#!/usr/bin/env ruby | |
# | |
# adb logcat をもっと見やすく. | |
# | |
require 'optparse' | |
# | |
# global option. | |
# | |
options = { | |
:loglevels => ['D'], | |
:tags => [], | |
:command => 'adb logcat -v tag', | |
:format => '[$tag]\n\t$msg', | |
:format_tag => "$tag", | |
:format_msg => "$msg", | |
:format_level => "$level", | |
:coloring => true, | |
:level_colors => { | |
'D' => 'blue', | |
'I' => 'green', | |
'W' => 'yellow', | |
'E' => 'red', | |
}, | |
:system_tags => [ | |
'AbsListView', | |
'ActivityManager', | |
'AlarmManagerService', | |
'AndroidRuntime', | |
'ApplicationPolicy', | |
'AudioHardwareALSA', | |
'AudioStreamOutALSA', | |
'AwesomePlayer', | |
'AlarmItem', | |
'AlarmWidget', | |
'AlarmReceiver', | |
'accuweather', | |
'alsa_ucm', | |
'ALSAModule', | |
'ANDROID_DRM_TEST', | |
'AlarmProvider', | |
'AudioPolicyManagerBase', | |
'AudioService', | |
'BatteryService', | |
'CircleLockScreen', | |
'CircleMissedEventWidget', | |
'CircleShortcutWidget', | |
'CircleUnlockRipple', | |
'CircleUnlockRippleRenderer', | |
'ClockWidget', | |
'ConnectivityService', | |
'comsamsunglog', | |
'DEFERED_APP_VISIBILITY', | |
'DrmPVPlugIn', | |
'dalvikvm', | |
'FastDormancy', | |
'InputReader', | |
'KeyguardViewManager', | |
'KeyguardUpdateMonitor', | |
'KeyguardViewMediator', | |
'LibQmg_native', | |
'LockPatternKeyguardView', | |
'MtpService', | |
'MTPJNIInterface', | |
'memalloc', | |
'MSC_Accu_Daemon', | |
'MobileDataStateTracker', | |
'NetworkConnectivityReceiver', | |
'NetworkManagementService', | |
'OMXCodec', | |
'OpenGLRenderer', | |
'PhoneStatusBar', | |
'PointerInterceptView', | |
'PopupuiReceiver', | |
'ANDROID_DRM_TEST', | |
'AlarmProvider', | |
'AudioPolicyManagerBase', | |
'AudioService', | |
'BatteryService', | |
'CircleLockScreen', | |
'CircleMissedEventWidget', | |
'CircleShortcutWidget', | |
'CircleUnlockRipple', | |
'CircleUnlockRippleRenderer', | |
'ClockWidget', | |
'ConnectivityService', | |
'comsamsunglog', | |
'DEFERED_APP_VISIBILITY', | |
'DrmPVPlugIn', | |
'dalvikvm', | |
'FastDormancy', | |
'InputReader', | |
'KeyguardViewManager', | |
'KeyguardUpdateMonitor', | |
'KeyguardViewMediator', | |
'LibQmg_native', | |
'LockPatternKeyguardView', | |
'MtpService', | |
'MTPJNIInterface', | |
'memalloc', | |
'MSC_Accu_Daemon', | |
'MobileDataStateTracker', | |
'NetworkConnectivityReceiver', | |
'NetworkManagementService', | |
'OMXCodec', | |
'OpenGLRenderer', | |
'PhoneStatusBar', | |
'PointerInterceptView', | |
'PopupuiReceiver', | |
'PVPlayReadyReceiver', | |
'PowerManagerService', | |
'SurfaceFlinger', | |
'SystemClock', | |
'SensorManager', | |
'StatusChecker', | |
'SignalStrength', | |
'SMD', | |
'ThermistorObserver', | |
'UsbDeviceManager', | |
'UsbDetectingManager', | |
'UsbDeviceManager', | |
'VolumePanel', | |
'WallpaperWidget', | |
'WindowManager', | |
'WifiService', | |
], | |
} | |
color_pallet = { | |
"black" => 30, | |
"red" => 31, | |
"yellow" => 33, | |
"blue" => 34, | |
"magenta" => 35, | |
"cyan" => 36, | |
"white" => 37, | |
} | |
# | |
# option parse | |
# | |
opt = OptionParser.new | |
opt.on('-l LEVELS', | |
"log level which is separated by comma. it should be V or D or I or W or E") do |v| | |
options[:loglevels] = v.upcase.split(',') | |
end | |
opt.on('-t TAGS', 'filtering tag') do |v| | |
options[:tags] = v.split(',') | |
end | |
opt.on('-f format', 'set specified format') do |v| | |
options[:format] = v | |
end | |
opt.on('--[no-]color', 'set coloring') do |v| | |
options[:coloring] = v | |
end | |
opt.parse!(ARGV) | |
# | |
# main | |
# | |
IO.popen(options[:command], 'r+') do |io| | |
io.each do |line| | |
line.chomp! | |
line.encode!("UTF-8", "UTF-8", | |
invalid: :replace, | |
undef: :replace, | |
replace: '.') | |
if %r{^(V|D|I|W|E)/(\w+):\s*(.+)} =~ line | |
level = $1 | |
tag = $2 | |
msg = $3 | |
next if !options[:loglevels].include?(level) | |
next if !options[:tags].empty? && !options[:tags].include?(tag) | |
next if options[:system_tags].include?(tag) | |
# coloring | |
if options[:coloring] && options[:level_colors][level] != nil then | |
color_format = "\033[%dm%s\033[0m" | |
color = color_pallet[options[:level_colors][level]] | |
level = color_format % [color, level] | |
tag = color_format % [color, tag] | |
msg = color_format % [color, msg] | |
end | |
# formating | |
outstr = options[:format] | |
.gsub(options[:format_level], level) | |
.gsub(options[:format_tag], tag) | |
.gsub(options[:format_msg], msg) | |
.gsub('\n', "\n") | |
.gsub('\t', "\t") | |
puts outstr | |
end | |
end | |
end | |
__END__ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment