summaryrefslogtreecommitdiff
path: root/tools/log-strip.py
blob: 3c8ca938ff0bc32a9db3d8a88141a54e43a76a19 (plain)
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
#!/usr/bin/python
"""
Strip varying data (PIDs, pointer values) from Gabble logs to make them
easier to compare.
"""

from __future__ import with_statement

import re
import sys

def sanitise(line):
    return (
        re.sub('^(\*\* )?\(telepathy-gabble:\d+\)', '',
        re.sub('\x1b\[0m', '',
        re.sub('^RECV \[\d+\]', 'RECV [???]',
        re.sub('0x[0-9A-Fa-f]{5,8}', '0x???????',
        re.sub("('?<[^ ]+ [^>]*id=)[\"'][^\"']+[\"']",
            lambda m: m.group(1) + '"?????"', line))))))

def process(file):
    for line in file:
        print sanitise(line),

def main():
    if len(sys.argv) > 1:
        for fn in sys.argv[1:]:
            with open(fn) as f:
                process(f)
    else:
        process(sys.stdin)

if __name__ == '__main__':
    main()