Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 67 lines (54 sloc) 1.467 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
#!/usr/bin/env python2

##
## Cherokee trace colorizer
##
## If cherokee is compiled with the --enable-trace parameter, it can
## be traced by using the CHEROKEE_TRACE environment variable or
## cherokee-tweak.
##
## Copyright: Alvaro Lopez Ortega <alvaro@alobbs.com>
## Licensed: GPL v2
##

import sys

RESET_COLOR = "\033[0m"
HIGHLIGHT = "\033[1;31;40m"

_threads = {}
_colors = []
_color_n = 0

def build_colors():
    global _colors
    for a in range(40,48):
        for b in range(30,38):
            if a-10 == b:
                continue
            color = '\033[0;%d;%dm' % (a,b)
            _colors.append(color)

def thread_color (thread):
    global _threads
    global _color_n
    if not thread in _threads.keys():
        color = _colors[_color_n]
        _threads[thread] = color
        _color_n += 1
    return _threads[thread]

def main():
    build_colors()

    while True:
        line = sys.stdin.readline()
        if len(line) < 1:
            break

        # Thread
        thread = None
        if line[0] == '{':
            end = line.find('}')
            if end > 0:
                thread = line[1:end]
                color = thread_color (thread)
                line = '%s%s%s %s' % (color, thread, RESET_COLOR, line[end+2:])

        # Words
        for w in sys.argv:
            line = line.replace(w, HIGHLIGHT + w + RESET_COLOR)

        # Nothing else to do..
        print line,

if __name__ == '__main__':
    main()
Something went wrong with that request. Please try again.