X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=resources%2Fcommons%2Fpplog.py;fp=resources%2Fcommons%2Fpplog.py;h=8cc4e3d265336c5f2fbc476ccefd0c08ca1e74b0;hb=f03fa74c52d00b5550c2d0bae162044818ff6f37;hp=0000000000000000000000000000000000000000;hpb=1ad7195fa2f695da6ccaef020e8d2b87d7a5fcb1;p=netvirt.git diff --git a/resources/commons/pplog.py b/resources/commons/pplog.py new file mode 100755 index 0000000000..8cc4e3d265 --- /dev/null +++ b/resources/commons/pplog.py @@ -0,0 +1,69 @@ +#!/usr/bin/python + +import string +from sys import stdout,stdin,argv,exit + +if len(argv) > 1 and argv[1] in ['-h', '-?', '--h', '--help']: + print 'pplog.py pretty prints Open Daylight log lines, useful for lines containing large nested objects' + print 'Usage: Simply pipe the lines you are interested through this script' + exit(0) + +line_num = 0 +def nl(): + global line_num + line_num += 1 + stdout.write('\n' + i) + +for l in stdin: + if '|' not in l: continue + + (t, level, component, cat, art, msg) = string.split(l, '|', maxsplit=5) + + I = ' ' + opener = '[{<' + closer = ']}>' + i = '' + + in_ws = 1 + is_empty_list = 0 + last_char = '' + title = '' + title_stack = [] + + for c in msg: + if in_ws and c in ' \t': continue + in_ws = 0 + + if c in closer: + i = i[:-2] + if not is_empty_list and last_char not in closer: nl() + in_ws = 1 + is_empty_list = 0 + title = '' + elif is_empty_list: + is_empty_list = 0 + nl() + + if last_char in closer and c != ',': nl() + + stdout.write(c) + if not c in opener: title += c + last_char = c + + if c in closer: + if len(title_stack): + (t,ln) = title_stack.pop() + if (line_num - ln) > 5: stdout.write(' /* ' + t.strip() + ' */') + + if c in opener: + i += I + in_ws = 1 + is_empty_list = 1 + if title: + title_stack.append((title, line_num)) + title = '' + + if c == ',': + nl() + in_ws = 1 + title = ''