JournalHandler: Sanitize extra fields to be valid journald fields
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 38/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Estancado
- Stack tecnológico
- python
- Área
- observability
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- C
- Estrellas
- 522
- Forks
- 79
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de systemd/python-systemd
-
Dificultad 3/5 1-2 días Aptitud para principiantes 48/100
systemd/python-systemd#177 · 1 comentario · 1 reacción ·
-
Dificultad 3/5 1-2 días Aptitud para principiantes 42/100
systemd/python-systemd#169 · 1 comentario ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
systemd/python-systemd#167 · 19 comentarios ·
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
systemd/python-systemd#152 · 1 comentario · 13 reacciones ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 45/100
systemd/python-systemd#146 · 2 comentarios ·
Todos los issues de systemd/python-systemd
Issues similares
-
Broadcast Documentation Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 90/100
kovidgoyal/kitty#10516 ·
-
libc
Dificultad 2/5 1-2 días Aptitud para principiantes 76/100
llvm/llvm-project#225506 · 1 comentario ·
-
enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
-
Status: Waiting triage Type: Bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
nanoframework/Home#1857 ·
-
bug
Dificultad 2/5 Medio día Aptitud para principiantes 82/100