Skip to content

Create JSONL structured log implementation

Log in JSON format so that log entries can be parsed by other tools (e.g. fluent-bit log forwarder) without the need to write a custom log parser.

Example log line uploaded to AWS image

Example JSON lines structured log log.jsonl:

{"time": "2023-10-04 08:55:12.964","log_level": "INFO","message": "Application initialized.","call_chain": "Experiment Pane.lvlib:Main.vi:4140011->Experiment Pane.lvlib:Main.vi.ACBRProxyCaller.C3000E8","error_code": "0"}
{"time": "2023-10-04 08:55:12.964","log_level": "DEBUG","message": "Running Self-Tests","call_chain": "Experiment Pane.lvlib:Main.vi:4140011->Experiment Pane.lvlib:Main.vi.ACBRProxyCaller.C3000E8","error_code": "0"}
{"time": "2023-10-04 08:55:12.964","log_level": "WARNING","message": "Self-Test A failed","call_chain": "Experiment Pane.lvlib:Main.vi:4140011->Experiment Pane.lvlib:Main.vi.ACBRProxyCaller.C3000E8","error_code": "1234"}
{"time": "2023-10-04 08:55:12.964","log_level": "ERROR","message": "VISA Could not load resource.","call_chain": "Experiment Pane.lvlib:Main.vi:4140011->Experiment Pane.lvlib:Main.vi.ACBRProxyCaller.C3000E8","error_code": "5678"}

Features:

  • Follows JSONlines format - https://jsonlines.org/
  • One log entry per line
  • Each log entry is JSON formatted
  • Each line is separated by line feed
  • Can expand single-line JSON using built in formatters in most text IDEs (i.e. VSCode, Shift+Alt+F)
  • Scalable - can easily include nested JSON structures