def format_line(entry, minlvl, highlight=False): if highlight: # level doesn't matter return ansi.format(str(entry), ['bold', 'yellow']) if entry.loglevel < minlvl: return None if entry.loglevel == argoslog.LOG_DEBUG: return ansi.format(str(entry), ['green']) elif entry.loglevel == argoslog.LOG_DATA: return str(entry) elif entry.loglevel == argoslog.LOG_INFO: return str(entry) elif entry.loglevel == argoslog.LOG_WARN: return ansi.format(str(entry), ['bold', 'cyan']) elif entry.loglevel == argoslog.LOG_ERR: return ansi.format(str(entry), ['bold', 'red']) elif entry.loglevel == argoslog.LOG_CRIT: return ansi.format(str(entry), ['bold', 'red']) else: return ansi.format("[unrecognized loglevel] ", ['bold', 'red']), str(entry)
def bad_line_handler(line): if (pat is not None) and (pat.search(line) is not None): print >>out, ansi.format(line, ['bold', 'yellow']) else: print >>out, ansi.format(line, ['bold', 'cyan'])
def writecol(self, index, text, ansicodes=[], wrap=True, border=False, center=False, padding=(0,0,0,0)): self.colbufs[index] = [] ansistart = ansi.format("", ansicodes, reset=False) ansistop = ansi.format("", ["reset"], reset=False) if border: width = self.colwidth - 4 - padding[2] - padding[3] else: width = self.colwidth - padding[2] - padding[3] lines = [] for i in range(padding[0]): # prevent ansi formatting from covering blank spaces lines.append(ansistop + " "*width + ansistart) if type(text) == types.StringType: text = [ text ] for textline in text: extra = width - len(textline) if extra >= 0: if center: # prevent ansi formatting from covering blank spaces lines.append(ansistop + " "*(extra/2) + ansistart + textline + ansistop + (" "*(extra - (extra/2))) + ansistart) else: # prevent ansi formatting from covering blank spaces lines.append(textline + ansistop + " "*extra + ansistart) elif wrap: for line in textwrap.TextWrapper(width=width).wrap(textline): lines.append(line.ljust(width)) else: # truncate text lines.append(textline[:width]) for i in range(padding[1]): # prevent ansi formatting from covering blank spaces lines.append(ansistop + " "*width + ansistart) if border: if type(border) == types.StringType: if len(border) > 1: raise ValueError("border must be either a boolean or a single character") horiz = ansistart + " " + border*(self.colwidth-2) + " " + ansistop sidechar = border elif type(border) != types.BooleanType: raise ValueError("border must be either a boolean or a single character") else: # border == True, use default characters horiz = ansistart + " " + "-"*(self.colwidth-2) + " " + ansistop sidechar = "|" # put the padding INSIDE the side-border (which, in turn, is inside # the ansi codes) prefix = ansistart + sidechar + " " + " "*padding[2] suffix = " "*padding[3] + " " + sidechar + ansistop else: # put the padding OUTSIDE the ansi codes prefix = " "*padding[2] + ansistart suffix = ansistop + " "*padding[3] if border: self.colbufs[index].append(horiz) for line in lines: self.colbufs[index].append(prefix + line + suffix) if border: self.colbufs[index].append(horiz)