Coverage for .nox/test-3-9/lib/python3.9/site-packages/nskit/common/logging/formatter.py: 75%

8 statements  

« prev     ^ index     » next       coverage.py v7.4.2, created at 2024-02-25 17:38 +0000

1"""LoggingFormatter with extra.""" 

2from logzero import LogFormatter as _LogFormatter 

3 

4BASE_FORMAT_STR = '%(color)s %(levelname)s: %(name)s - %(asctime)-15s: %(message)s - %(extra)s :: %(filename)s:%(funcName)s' # noqa: E501 

5 

6 

7class LoggingFormatter(_LogFormatter): 

8 """Add extra to record.""" 

9 

10 def format(self, record): 

11 """Format the record with extra attribute.""" 

12 record.extra = getattr(record, 'extra', {}) 

13 return super().format(record) 

14 

15 

16def get_library_log_format_string(library, version): 

17 """Get a log format string including the library name and version.""" 

18 return BASE_FORMAT_STR.replace('%(name)s', f'{library}:{version} - %(name)s')