JournalHandler: Sanitize extra fields to be valid journald fields
還沒有人認領這個 Issue。
評估
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 新手友好度
- 38/100
- Issue 類型
- 缺陷
- 描述清晰度
- 基本清楚
- 活躍度
- 停滯
- 技術堆疊
- python
研究方向
Start at the Python systemd.journal JournalHandler entry point and compare its handling of logging extra fields with the sanitation code linked from cysystemd/_journal.pyx. Verify the behavior using the structured_data logging example; done means valid extra fields are no longer silently omitted by journald.
由索引模型根據 Issue 內容生成。
描述
I noticed an incontinence with JournalHandler when using it in an existing code base. I already use the Python logging module and all my logging already includes structured data like this:
LOG.info('test', extra={'structured_data': 23})
The structured_data field does not make it into journald and is silently omitted. I checked https://github.com/mosquito/cysystemd and it has sanitation code which works for me:
As the status of this project and relationship with https://github.com/mosquito/cysystemd is not clear I just wanted to document this here.
Edit:
I ended up using python-systemd instead of cysystemd mainly because of the less cluttered fields it outputs so I needed to work around the issue described here. I needed to workaround another limitation which is that journald cannot handle nested fields so I combined the two workarounds into this (also I want to log sets so it includes a workaround for this as well):
import logging
import json
from systemd.journal import JournalHandler
class SetJSONEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, set):
return list(obj)
return json.JSONEncoder.default(self, obj)
class LogExtraAsJsonDataAdapter(logging.LoggerAdapter):
def process(self, msg, kwargs):
if 'extra' in kwargs:
kwargs['extra'] = {'JSON_SD': json.dumps(kwargs['extra'], cls=SetJSONEncoder)}
return msg, kwargs
_LOG = logging.getLogger(__name__)
_LOG.addHandler(JournalHandler())
LOG = LogExtraAsJsonDataAdapter(_LOG, {})
The idea here is that Journalbeat sends those logs to Logstash where JSON_SD is JSON decoded and included into the log event.
- 主要語言
- C
- 星號
- 522
- 分支
- 79
- PR 合併指標
- 30 天內沒有已合併 PR
環境準備
我們還沒有檢查這個專案的環境設定檔。先看它的 README,通用步驟見我們的新手貢獻指南。
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
systemd/python-systemd 的其他 Issue
-
難度 3/5 1-2 天 新手友好度 48/100
systemd/python-systemd#177 · 1 則留言 · 1 個 reaction ·
-
難度 3/5 1-2 天 新手友好度 42/100
systemd/python-systemd#169 · 1 則留言 ·
-
難度 4/5 3-5 天 新手友好度 48/100
systemd/python-systemd#167 · 19 則留言 ·
-
難度 5/5 一週以上 新手友好度 35/100
systemd/python-systemd#152 · 1 則留言 · 13 個 reaction ·
-
難度 4/5 3-5 天 新手友好度 45/100
systemd/python-systemd#146 · 2 則留言 ·
查看 systemd/python-systemd 的全部 Issue
相似的 Issue
-
bug needs triage
難度 2/5 1-3 小時 新手友好度 78/100
netdata/netdata#24062 · 1 則留言 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 76/100
-
難度 2/5 1-3 小時 新手友好度 88/100
BasedHardware/omi#19463 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 72/100
EchoTools/nevr-runtime#30 ·
-
難度 2/5 1-3 小時 新手友好度 88/100
riscv-software-src/riscv-isa-sim#2448 ·
維護者通常 2 天內回覆