| Total Complexity | 4 |
| Total Lines | 23 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import logging |
||
| 2 | import os |
||
| 3 | import sys |
||
| 4 | |||
| 5 | |||
| 6 | class RelpathFormatFilter(logging.Filter): |
||
| 7 | """Adds '%(relpath)s' as a 'LogRecord' attribute.""" |
||
| 8 | |||
| 9 | def filter(self, record): |
||
| 10 | pathname = record.pathname |
||
| 11 | record.relpath = None |
||
| 12 | abs_sys_paths = map(os.path.abspath, sys.path) |
||
| 13 | for path in sorted(abs_sys_paths, key=len, reverse=True): |
||
| 14 | if not path.endswith(os.sep): |
||
| 15 | path += os.sep |
||
| 16 | if pathname.startswith(path): |
||
| 17 | record.relpath = os.path.relpath(pathname, path) |
||
| 18 | break |
||
| 19 | return True |
||
| 20 | |||
| 21 | |||
| 22 | relpath_format_filter = RelpathFormatFilter() |
||
| 23 |