def trans_tag(self, tag, msg): if self.trans_tag_map is None or tag is None: return msg for key in self.trans_tag_map: if key in tag: prefix = self.trans_tag_map[key] return u'%s %s' % (colorize(prefix, bg=allocate_color(prefix)), msg) return msg
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())
def trans_msg(self, msg): if self.trans_msg_map is None: return msg for key in self.trans_msg_map: if msg.startswith(key): value = self.trans_msg_map[key] return u'| %s | %s' % (colorize(value, fg=allocate_color(value)), msg) return msg
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())
def process_decode_content(self, line, time, level, tag, process, thread, message): match_condition = True # filter if self.tag_keywords is not None and tag is not None: if not keywords_regex(tag, self.tag_keywords): match_condition = False self.pre_line_match = False else: self.pre_line_match = True if self.line_keywords is not None: if not keywords_regex(line, self.line_keywords): match_condition = False self.pre_line_match = False else: self.pre_line_match = True if match_condition and tag is None and not self.pre_line_match: match_condition = False # if 'special world' in line: # match_precondition = True if not match_condition: return None, None, None msgkey = None # the handled current line linebuf = '' # time if time is not None: time = time[-TIME_WIDTH:].rjust(TIME_WIDTH) linebuf += time linebuf += ' ' elif self.regex_parser.is_contain_time(): linebuf += ' ' * TIME_WIDTH linebuf += ' ' # thread if thread is not None: thread = thread.strip() thread = thread[-THREAD_WIDTH:].rjust(THREAD_WIDTH) linebuf += thread linebuf += ' ' elif self.regex_parser.is_contain_thread(): linebuf += ' ' * THREAD_WIDTH linebuf += ' ' # tag if tag is not None and (not self.hide_same_tags or tag != self.last_tag): self.last_tag = tag tag = tag.strip() color = allocate_color(tag) tag = tag.strip() tag = tag[-TAG_WIDTH:].rjust(TAG_WIDTH) linebuf += colorize(tag, fg=color) linebuf += ' ' elif self.regex_parser.is_contain_tag(): linebuf += ' ' * TAG_WIDTH linebuf += ' ' # level if level is not None: if level in TAGTYPES: linebuf += TAGTYPES[level] else: linebuf += ' ' + level + ' ' linebuf += ' ' elif self.regex_parser.is_contain_level(): linebuf += ' ' linebuf += ' ' # message # -separator if self.separator is not None: msgkey = self.separator.process(message) # -trans if self.trans is not None: message = self.trans.trans_msg(message) message = self.trans.hide_msg(message) message = self.trans.trans_tag(tag, message) if self.highlight_list is not None: for highlight in self.highlight_list: if highlight in message: message = message.replace( highlight, termcolor(fg=BLACK, bg=allocate_color(highlight)) + highlight + RESET) linebuf += message return msgkey, linebuf, match_condition