예제 #1
0
    def __init__(self, regex_exp):
        keys, regex = REGEX_EXP_RE.match(regex_exp).groups()
        process_key_order = keys.split(',')

        self.regex = re.compile(r"%s" % regex)
        for key in process_key_order:
            key = key.strip()
            if key in ALL_SUPPORT_KEY:
                self.key_order.append(key)
            else:
                print_warn("not support key[%s] only support: %s" % (key, ALL_SUPPORT_KEY))

        print("find regex: " + self.key_order.__str__() + " with " + regex)
예제 #2
0
    def __init__(self, regex_exp):
        keys, regex = REGEX_EXP_RE.match(regex_exp).groups()
        process_key_order = keys.split(',')

        self.regex = re.compile(r"%s" % regex)
        for key in process_key_order:
            key = key.strip()
            if key in ALL_SUPPORT_KEY:
                self.key_order.append(key)
            elif key == DEPRECATED_DATE_KEY:
                print_warn(
                    "please change 'data' to 'date' because this wrong word has been fixed on the current version, for the temporary we treat it as 'date'"
                )
                self.key_order.append('date')
            else:
                print_warn("not support key[%s] only support: %s" %
                           (key, ALL_SUPPORT_KEY))

        print("find regex: " + self.key_order.__str__() + " with " + regex)
예제 #3
0
def main():
    #print("-------------------------------------------------------")
    #print("                  OkCat v" + __version__)
    #print("")
    #print("Thanks for using okcat! Now, the doc is available on: ")
    #print_blue("        https://github.com/Jacksgong/okcat")
    #print("")
    #print("                   Have Fun!")
    #print("-------------------------------------------------------")

    parser = argparse.ArgumentParser(
        description='Filter logcat by package name')
    parser.add_argument(
        '-f',
        '--file',
        dest='package_or_path',
        nargs='*',
        help=
        'This can be Application package name(s) or log file path(if the file from path is exist)'
    )
    parser.add_argument('-y',
                        '--yml_file_name',
                        dest='yml',
                        help='Using yml file you config on ~/.okcat folder')
    parser.add_argument('--hide-same-tags',
                        dest='hide_same_tags',
                        action='store_true',
                        help='Do not display the same tag name')

    # following args are just for parser
    parser.add_argument(
        '-k',
        '--keyword',
        dest='keyword',
        action='append',
        help='You can filter you care about log by this keyword(s)')

    # following args are just for adb
    parser.add_argument('-w',
                        '--tag-width',
                        metavar='N',
                        dest='tag_width',
                        type=int,
                        default=23,
                        help='Width of log tag')
    parser.add_argument('-l',
                        '--min-level',
                        dest='min_level',
                        type=str,
                        choices=LOG_LEVELS + LOG_LEVELS.lower(),
                        default='V',
                        help='Minimum level to be displayed')
    parser.add_argument('--color-gc',
                        dest='color_gc',
                        action='store_true',
                        help='Color garbage collection')
    parser.add_argument('--current',
                        dest='current_app',
                        action='store_true',
                        help='Filter logcat by current running app')
    parser.add_argument('-s',
                        '--serial',
                        dest='device_serial',
                        help='Device serial number (adb -s option)')
    parser.add_argument('-d',
                        '--device',
                        dest='use_device',
                        action='store_true',
                        help='Use first device for log input (adb -d option)')
    parser.add_argument(
        '-e',
        '--emulator',
        dest='use_emulator',
        action='store_true',
        help='Use first emulator for log input (adb -e option)')
    parser.add_argument('-c',
                        '--clear',
                        dest='clear_logcat',
                        action='store_true',
                        help='Clear the entire log before running')
    parser.add_argument('-t',
                        '--tag',
                        dest='tag',
                        action='append',
                        help='Filter output by specified tag(s)')
    parser.add_argument('-tk',
                        '--tag_keywords',
                        dest='tag_keywords',
                        nargs='*',
                        help='Filter output by specified tag keyword(s)')
    parser.add_argument('-lk',
                        '--line_keywords',
                        dest='line_keywords',
                        nargs='*',
                        help='Filter output by specified line_keyword(s)')
    parser.add_argument('-hl',
                        '--highlight-list',
                        dest='highlight_list',
                        nargs='*',
                        help='Highlight messages')
    parser.add_argument('-i',
                        '--ignore-tag',
                        dest='ignored_tag',
                        action='append',
                        help='Filter output by ignoring specified tag(s)')
    parser.add_argument('-p',
                        '--parse-start-proc',
                        dest='parse_start_proc',
                        action='store_true',
                        default=False,
                        help='Parse_start_proc')
    parser.add_argument('-a',
                        '--all',
                        dest='all',
                        action='store_true',
                        default=False,
                        help='Print all log messages')

    # help
    if len(argv) == 2 and argv[1] == 'help':
        exit()

    args = parser.parse_args()
    if args.package_or_path is None:
        args.package_or_path = []
    file_paths = []
    candidate_path = args.package_or_path
    for path in candidate_path:
        if is_path(path):
            file_paths.append(path)
    print(file_paths)
    if file_paths:
        # # if args.yml is None:
        #     print("")
        #     print_exit("Please using '-y=conf-name' to provide config file to parse this log file.")
        #     print("The config file is very very simple! More detail about config file please move to : https://github.com/Jacksgong/okcat")
        #     print("")
        #     print("-------------------------------------------------------")
        #     exit()

        print("start analyse log")
        parser = LogFileParser(file_paths, args.hide_same_tags)
        parser.setup(args.yml, args)
        parser.process()
    else:
        is_interrupt_by_user = False

        _adb = Adb()
        while True:
            try:
                _adb.setup(args)
                _adb.loop()
            except KeyboardInterrupt:
                print_warn('interrupt by user')
                is_interrupt_by_user = True

            if is_interrupt_by_user:
                break
            else:
                print_warn('ADB CONNECTION IS LOST. Retry...')
예제 #4
0
def main():
    print("-------------------------------------------------------")
    print("                  OkCat v" + __version__)
    print ""
    print "Thanks for using okcat! Now, the doc is available on: "
    print_blue("        https://github.com/Jacksgong/okcat")
    print ""
    print "                   Have Fun!"
    print("-------------------------------------------------------")

    parser = argparse.ArgumentParser(description='Filter logcat by package name')
    parser.add_argument('package_or_path', nargs='*',
                        help='This can be Application package name(s) or log file path(if the file from path is exist)')
    parser.add_argument('-y', '--yml_file_name', dest='yml', help='Using yml file you config on ~/.okcat folder')
    parser.add_argument('--hide-same-tags', dest='hide_same_tags', action='store_true',
                        help='Do not display the same tag name')

    # following args are just for parser
    # parser.add_argument('-k', '--keyword', dest='keyword', action='append', help='You can filter you care about log by this keyword(s)')

    # following args are just for adb
    parser.add_argument('-w', '--tag-width', metavar='N', dest='tag_width', type=int, default=23,
                        help='Width of log tag')
    parser.add_argument('-l', '--min-level', dest='min_level', type=str, choices=LOG_LEVELS + LOG_LEVELS.lower(),
                        default='V', help='Minimum level to be displayed')
    parser.add_argument('--color-gc', dest='color_gc', action='store_true', help='Color garbage collection')
    parser.add_argument('--current', dest='current_app', action='store_true',
                        help='Filter logcat by current running app')
    parser.add_argument('-s', '--serial', dest='device_serial', help='Device serial number (adb -s option)')
    parser.add_argument('-d', '--device', dest='use_device', action='store_true',
                        help='Use first device for log input (adb -d option)')
    parser.add_argument('-e', '--emulator', dest='use_emulator', action='store_true',
                        help='Use first emulator for log input (adb -e option)')
    parser.add_argument('-c', '--clear', dest='clear_logcat', action='store_true',
                        help='Clear the entire log before running')
    parser.add_argument('-t', '--tag', dest='tag', action='append', help='Filter output by specified tag(s)')
    parser.add_argument('-tk', '--tag_keywords', dest='tag_keywords', action='append',
                        help='Filter output by specified tag keyword(s)')
    parser.add_argument('-i', '--ignore-tag', dest='ignored_tag', action='append',
                        help='Filter output by ignoring specified tag(s)')
    parser.add_argument('-a', '--all', dest='all', action='store_true', default=False,
                        help='Print all log messages')

    # help
    if len(argv) == 2 and argv[1] == 'help':
        exit()

    args = parser.parse_args()

    file_path = None
    candidate_path = args.package_or_path
    if candidate_path is not None and len(candidate_path) > 0 and is_path(candidate_path[0]):
        file_path = candidate_path[0]

    if file_path is None:
        is_interrupt_by_user = False

        _adb = Adb()
        _adb.setup(args)
        try:
            _adb.loop()
        except KeyboardInterrupt:
            is_interrupt_by_user = True

        if not is_interrupt_by_user:
            print_warn('ADB CONNECTION IS LOST.')
    else:
        parser = LogFileParser(file_path, args.hide_same_tags)
        parser.setup(args.yml)
        parser.process()