vectorgrp / sil-kit

Vector SIL Kit – Open-Source Library for Connecting Software-in-the-Loop Environments
https://vectorgrp.github.io/sil-kit-docs
MIT License
107 stars 32 forks source link

SILKIT-1535: Configuration for structured logging #52

Closed VLukasBecker closed 3 months ago

VLukasBecker commented 5 months ago

Subject

Adds the configuration option to output log messages in a structure JSON format.

Instructions for review / testing

Developer checklist (address before review)

VDanielEdwards commented 3 months ago

@VLukasBecker I'm going to run a few manual tests across a Linux VM and Windows.

VDanielEdwards commented 3 months ago

I love it! As an experiment, I changed the 'Updating participant status' message in SystemStateTracker.cpp to use the new LoggerMessage and the results are great:

Log::LoggerMessage lm{_logger, Log::Level::Debug};
lm.SetMessage("Updating participant status");
lm.SetKeyValue("participant name", participantName);
lm.SetKeyValue("old participant state", fmt::to_string(oldParticipantState));
lm.SetKeyValue("new participant state", fmt::to_string(newParticipantState));
lm.Dispatch();

The 'simple' logger produces the following output:

[2024-07-25 13:17:23.558] [EthernetReader] [debug] Updating participant status, participant name: EthernetWriter, new participant state: Shutdown, old participant state: ShuttingDown

The JSON logger produces this (pretty-printed by jq):

{
  "ts": "1721906243558938",
  "log": "EthernetReader",
  "lvl": "debug",
  "msg": "Updating participant status",
  "kv": {
    "participant name": "EthernetWriter",
    "new participant state": "Shutdown",
    "old participant state": "ShuttingDown"
  }
}