JournalHandler: Sanitize extra fields to be valid journald fields
まだ誰も着手していません。
評価
- 難易度
- 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 はありません
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
systemd/python-systemd のほかの issue
-
難易度 3/5 1〜2日 初心者へのやさしさ 48/100
systemd/python-systemd#177 · コメント 1 件 · リアクション 1 件 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 42/100
systemd/python-systemd#169 · コメント 1 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
systemd/python-systemd#167 · コメント 19 件 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
systemd/python-systemd#152 · コメント 1 件 · リアクション 13 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
systemd/python-systemd#146 · コメント 2 件 ·
systemd/python-systemd の issue をすべて見る
似ている issue
-
Status: Waiting triage Type: Bug
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
nanoframework/Home#1857 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
libsdl-org/SDL#16372 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
corazawaf/coraza-nginx#140 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100