fluent / fluent/fluent-logger-python

Formatting exception handling and fill_missing_fmt_key error

Đang mở
#189 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Python
Star
457
Fork
138
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

There is **ValueError** is reraised instead of KeyError in the format method of each style class since python3.8:
https://github.com/python/cpython/issues/79025#issuecomment-1093800953

So formatting error handling and **fill_missing_fmt_key=True** arg of FluentRecordFormatter does not work correctly.
```
Traceback (most recent call last):
File "/usr/lib/python3.10/logging/__init__.py", line 440, in format
return self._format(record)
File "/usr/lib/python3.10/logging/__init__.py", line 458, in _format
return self._fmt.format(**values)
KeyError: 'kubernetes'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/nz/.local/lib/virtualenvs/platform10/lib/python3.10/site-packages/django/core/management/base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/nz/.local/lib/virtualenvs/platform10/lib/python3.10/site-packages/django/core/management/commands/runserver.py", line 61, in execute
super().execute(*args, **options)
File "/home/nz/.local/lib/virtualenvs/platform10/lib/python3.10/site-packages/django/core/management/base.py", line 371, in execute
output = self.handle(*args, **options)
File "/home/nz/.local/lib/virtualenvs/platform10/lib/python3.10/site-packages/django/core/management/commands/runserver.py", line 96, in handle
self.run(**options)
File "/home/nz/.local/lib/virtualenvs/platform10/lib/python3.10/site-packages/django/core/management/commands/runserver.py", line 103, in run
autoreload.run_with_reloader(self.inner_run, **options)
File "/home/nz/.local/lib/virtualenvs/platform10/lib/python3.10/site-packages/django/utils/autoreload.py", line 617, in run_with_reloader
logger.info('Watching for file changes with %s', reloader.__class__.__name__)
File "/usr/lib/python3.10/logging/__init__.py", line 1477, in info
self._log(INFO, msg, args, **kwargs)
File "/usr/lib/python3.10/logging/__init__.py", line 1624, in _log
self.handle(record)
File "/usr/lib/python3.10/logging/__init__.py", line 1634, in handle
self.callHandlers(record)
File "/usr/lib/python3.10/logging/__init__.py", line 1696, in callHandlers
hdlr.handle(record)
File "/usr/lib/python3.10/logging/__init__.py", line 968, in handle
self.emit(record)
File "/home/nz/.local/lib/virtualenvs/platform10/lib/python3.10/site-packages/fluent/handler.py", line 232, in emit
data = self.format(record)
File "/usr/lib/python3.10/logging/__init__.py", line 943, in format
return fmt.format(record)
File "/home/nz/.local/lib/virtualenvs/platform10/lib/python3.10/site-packages/fluent/handler.py", line 97, in format
data = self._formatter(record)
File "/home/nz/.local/lib/virtualenvs/platform10/lib/python3.10/site-packages/fluent/handler.py", line 154, in _format_by_dict
raise exc
File "/home/nz/.local/lib/virtualenvs/platform10/lib/python3.10/site-packages/fluent/handler.py", line 148, in _format_by_dict
value = self.__style(value).format(record)
File "/usr/lib/python3.10/logging/__init__.py", line 442, in format
raise ValueError('Formatting field not found in record: %s' % e)
ValueError: Formatting field not found in record: 'kubernetes'
```
**ValueError** must be handled [here](https://github.com/fluent/fluent-logger-python/blob/ace80f4c2bd0020fc16891440243663c612dd01e/fluent/handler.py#L151)

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Hướng nghiên cứu

Start at fluent/handler.py around the linked line 151 and reproduce the Python 3.8+ formatting traceback. Trace how ValueError is handled for each style and how FluentRecordFormatter's fill_missing_fmt_key=True path responds; done means both formatting error handling and missing-key filling behave as intended.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
backend
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
45/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.