예제 #1
0
    def color_line(self, line):
        msg_key, line_buf, match_precondition = self.processor.process(line)

        if not match_precondition:
            return

        if msg_key is not None:
            print('')
            print_unicode(u''.join(colorize(msg_key + ": ", fg=allocate_color(msg_key))).encode('utf-8').lstrip())

        print_unicode(u''.join(line_buf).encode('utf-8').lstrip())
예제 #2
0
파일: adb.py 프로젝트: wipro940/okcat
    def loop(self):
        app_pid = None

        while self.adb.poll() is None:
            try:
                line = self.adb.stdout.readline()
            except KeyboardInterrupt:
                break
            if len(line) == 0:
                break

            line = line.decode('utf-8', 'replace').strip()
            if len(line) == 0:
                continue

            bug_line = BUG_LINE.match(line)
            if bug_line is not None:
                continue

            date, time, level, tag, owner, thread, message = self.log_regex.parse(
                line)
            if message is None:
                # print 'message is none with %s' % line
                continue

            tag = tag.strip()
            start = parse_start_proc(line)
            if start:
                line_package, target, line_pid, line_uid, line_gids = start
                if self.match_packages(line_package):
                    self.pids.add(line_pid)

                    app_pid = line_pid

                    linebuf = '\n'
                    linebuf += colorize(' ' * (self.header_size - 1), bg=WHITE)
                    linebuf += indent_wrap(' Process %s created for %s\n' %
                                           (line_package, target))
                    linebuf += colorize(' ' * (self.header_size - 1), bg=WHITE)
                    linebuf += ' PID: %s   UID: %s   GIDs: %s' % (
                        line_pid, line_uid, line_gids)
                    linebuf += '\n'
                    print(linebuf)

            dead_pid, dead_pname = self.parse_death(tag, message)
            if dead_pid:
                self.pids.remove(dead_pid)
                linebuf = '\n'
                linebuf += colorize(' ' * (self.header_size - 1), bg=RED)
                linebuf += ' Process %s (PID: %s) ended' % (dead_pname,
                                                            dead_pid)
                linebuf += '\n'
                print(linebuf)

            # Make sure the backtrace is printed after a native crash
            if tag == 'DEBUG':
                bt_line = BACKTRACE_LINE.match(message.lstrip())
                if bt_line is not None:
                    message = message.lstrip()
                    owner = app_pid

            # print '%s %s %s' % (owner, self.pids, tag)
            if not self.all and owner not in self.pids:
                continue
            if level in LOG_LEVELS_MAP and LOG_LEVELS_MAP[
                    level] < self.min_level:
                continue
            if self.ignored_tag and tag_in_tags_regex(tag, self.ignored_tag):
                continue
            if self.tag and not tag_in_tags_regex(tag, self.tag):
                continue

            msg_key, linebuf, match_precondition = self.processor.process_decode_content(
                line, time, level, tag, owner, thread, message)
            if not match_precondition or linebuf is None:
                continue

            if msg_key is not None:
                print('')
                print_unicode(u''.join(
                    colorize(
                        msg_key + ": ",
                        fg=allocate_color(msg_key))).encode('utf-8').lstrip())

            print_unicode(u''.join(linebuf).encode('utf-8').lstrip())