Skip to content

Instantly share code, notes, and snippets.

@riyadixitagra
Created March 24, 2023 14:12
Show Gist options
  • Save riyadixitagra/c251685c1ba84248181891f7bc282395 to your computer and use it in GitHub Desktop.
Save riyadixitagra/c251685c1ba84248181891f7bc282395 to your computer and use it in GitHub Desktop.
Aiming at highlighting the improvision in logging practices after migrating the pldm repository to Structured Log using LG2 api
PLDM repository was using standard ostream object std::cerr for logging errors and std::cout for logging information in journald. Following example shows an instance of log and the object it generates in journal json -
std::cerr << "test error logs0=" << 0 << ", log1=" << 1 <<", log2=" << 2 << "\n";
OR
int KEY0=0, KEY1= 1, KEY2= 2;
std::cerr << "test error logs0=" << KEY0 << ", log1=" << KEY1 << ", log2=" << KEY2 << "\n";
The journal object for above log -
{
"_GID" : "0",
"_COMM" : "pldmd",
"_UID" : "0",
"_SYSTEMD_INVOCATION_ID" : "1bc79b43d85246328c0f6cf2e328b410",
"SYSLOG_FACILITY" : "3",
"_SYSTEMD_CGROUP" : "/system.slice/pldmd.service",
"__CURSOR" : "s=534599b83ea34e4dbf1ff68da51ced52;i=854c;b=6fa9c9d600e842c5b0a8bb9c070c687f;m=15c5cd9714;t=5f79fcc39bfc3;x=a2720c8f2bbeb6",
"PRIORITY" : "6",
"_MACHINE_ID" : "07bc67637594463a9285ddbefc39d60b",
"_HOSTNAME" : "rain135bmc",
"_SYSTEMD_SLICE" : "system.slice",
"_CAP_EFFECTIVE" : "1ffffffffff",
"_CMDLINE" : "/home/service/riya_patch/pldmd",
"_TRANSPORT" : "stdout",
"_STREAM_ID" : "4906ff9f0bc1436e80c878fee69454a2",
"SYSLOG_IDENTIFIER" : "pldmd",
"__MONOTONIC_TIMESTAMP" : "93512898324",
"_SYSTEMD_UNIT" : "pldmd.service",
"_PID" : "5432",
"__REALTIME_TIMESTAMP" : "1679640581750723",
"_EXE" : "/home/service/riya_patch/pldmd",
"MESSAGE" : "test error logs0=0, log1=1, log2=2",
"_BOOT_ID" : "6fa9c9d600e842c5b0a8bb9c070c687f"
}
On the contrary migration to structured logging - lg2, there are additional parameters which is included in the object for ease of debugging, automation, etc. Following example shows an instance of log and the object it generates in journal json -
lg2::error("test error logs0= {KEY0}, log1= {KEY1}, log2={KEY2}", "KEY0", 0, "KEY1", 1, "KEY2", 2);
The journal object for above log -
{
"_HOSTNAME" : "rain104bmc",
"KEY1" : "1",
"LOG2_FMTMSG" : "test error logs0= {KEY0}, log1= {KEY1}, log2={KEY2}",
"SYSLOG_IDENTIFIER" : "pldmd",
"_EXE" : "/usr/bin/pldmd",
"_SYSTEMD_INVOCATION_ID" : "6eab343119fd4aefbf1f565c2aef825a",
"__MONOTONIC_TIMESTAMP" : "67972788",
"_SYSTEMD_UNIT" : "pldmd.service",
"_CAP_EFFECTIVE" : "1ffffffffff",
"_SYSTEMD_SLICE" : "system.slice",
"_GID" : "0",
"_CMDLINE" : "/usr/bin/pldmd",
"_UID" : "0",
"CODE_LINE" : "189",
"_SOURCE_REALTIME_TIMESTAMP" : "1675310600809551",
"_MACHINE_ID" : "505ed3f6b82f4f239d75a966db4affe9",
"CODE_FILE" : "/usr/src/debug/pldm/1.0+gitAUTOINC+4b02b23216-r1/pldmd/pldmd.cpp",
"KEY2" : "2",
"KEY0" : "0",
"CODE_FUNC" : "int main(int, char**)",
"PRIORITY" : "3",
"_TRANSPORT" : "journal",
"MESSAGE" : "test error logs0= 0, log1= 1, log2=2",
"__REALTIME_TIMESTAMP" : "1675310600812570",
"_SYSTEMD_CGROUP" : "/system.slice/pldmd.service",
"_PID" : "967",
"_COMM" : "pldmd",
"_BOOT_ID" : "a3394e0083c44757ad9c7c6b4c8885dc",
"__CURSOR" : "s=ca11bbefcf7e4743bdba64c9b214fff0;i=2ecad;b=a3394e0083c44757ad9c7c6b4c8885dc;m=40d2eb4;t=5f3afa53ff81a;x=14e013e38e1bcade"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment