← retour aux snippets

journalctl: exporter en JSON/NDJSON

Obtenir des logs journald en JSON pour traitement par jq ou ingestion.

bash monitoring #journalctl#json#logs

objectif

Faciliter l’analyse et l’export des logs.

code minimal

journalctl -u nginx -o json | jq -c . > nginx.ndjson

utilisation

# champs clés sur la période
journalctl -S "2025-08-15 00:00:00" -U "2025-08-16 00:00:00" -o json | jq -r '[.systemd_unit,.MESSAGE] | @tsv' | head

variante(s) utile(s)

# JSON pretty (moins compact)
journalctl -o json-pretty -n 50

notes

  • -o json émet un objet par ligne (NDJSON).
  • utilisez des filtres -u, -g, _PID= pour cibler.