fluent / fluent/fluent-logger-python
Formatting exception handling and fill_missing_fmt_key error
- 主要語言
- Python
- 星號
- 457
- 分支
- 138
- PR 合併指標
- 30 天內沒有已合併 PR
描述
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)
貢獻指南
這個儲存庫沒有索引到貢獻指南
研究方向
從 fluent/handler.py 中連結所指向的第 151 行附近開始,並重現 Python 3.8+ 的格式化 traceback。追蹤每種樣式如何處理 ValueError,以及 FluentRecordFormatter 的 fill_missing_fmt_key=True 路徑如何回應;當格式化錯誤處理和缺少鍵的填入都如預期運作時,即表示完成。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- backend
- Issue 類型
- 缺陷
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100