Enable `lg2` logs to be printed to stderr in test

Signed-off-by: Zane Shelley <zshelle@us.ibm.com>
Change-Id: Ie4922b3bf6adeeb1e6dbe8db7e76ed8ae605d754
diff --git a/test/meson.build b/test/meson.build
index ef8a3a9..e1ab8bb 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -62,11 +62,13 @@
 test_deps = [
   libhei_dep,
   libpdbg_dep,
+  phosphor_logging_dep,
   gtest_dep,
 ]
 
 test_vars = [
   pdbg_env,
+  'LG2_FORCE_STDERR=true',
 ]
 
 test_util_lib = static_library('test_util_lib',
diff --git a/test/pdbg-sim-only.cpp b/test/pdbg-sim-only.cpp
index 2e81fe5..98519d3 100644
--- a/test/pdbg-sim-only.cpp
+++ b/test/pdbg-sim-only.cpp
@@ -9,8 +9,8 @@
 #include <assert.h>
 
 #include <test/sim-hw-access.hpp>
+#include <util/log.hpp>
 #include <util/pdbg.hpp>
-#include <util/trace.hpp>
 
 //------------------------------------------------------------------------------
 
@@ -47,8 +47,10 @@
 
     if (0 != rc)
     {
-        trace::err("SCOM read failure: target=%s addr=0x%0" PRIx64,
-                   getPath(i_target), i_addr);
+        lg2::error(
+            "SCOM read failure: target={SCOM_TARGET} addr={SCOM_ADDRESS}",
+            "SCOM_TARGET", getPath(i_target), "SCOM_ADDRESS",
+            (lg2::hex | lg2::field64), i_addr, "SCOM_ACCESS_RC", rc);
     }
 
     return rc;
@@ -65,8 +67,10 @@
 
     if (0 != rc)
     {
-        trace::err("CFAM read failure: target=%s addr=0x%08x",
-                   getPath(i_target), i_addr);
+        lg2::error(
+            "CFAM read failure: target={CFAM_TARGET} addr={CFAM_ADDRESS}",
+            "CFAM_TARGET", getPath(i_target), "CFAM_ADDRESS",
+            (lg2::hex | lg2::field32), i_addr, "CFAM_ACCESS_RC", rc);
     }
 
     return rc;
diff --git a/util/log.hpp b/util/log.hpp
new file mode 100644
index 0000000..14def78
--- /dev/null
+++ b/util/log.hpp
@@ -0,0 +1,14 @@
+#pragma once
+
+// C++20 projects should use `lg2` over `log`, when possible. See the following
+// for details on structured logging:
+//   https://github.com/openbmc/phosphor-logging/blob/master/docs/structured-logging.md
+
+#include <phosphor-logging/lg2.hpp>
+
+// This allows for easier use of string literals (i.e. `"foo"s`). See the
+// following for details:
+//   https://en.cppreference.com/w/cpp/string/basic_string/operator%22%22s
+
+#include <string>
+using namespace std::string_literals;
diff --git a/util/pdbg-no-sim.cpp b/util/pdbg-no-sim.cpp
index 87b49cf..d7b7f90 100644
--- a/util/pdbg-no-sim.cpp
+++ b/util/pdbg-no-sim.cpp
@@ -13,6 +13,7 @@
 #include <libpdbg_sbe.h>
 }
 
+#include <util/log.hpp>
 #include <util/pdbg.hpp>
 #include <util/trace.hpp>
 
@@ -68,8 +69,10 @@
 
     if (0 != rc)
     {
-        trace::err("SCOM read failure: target=%s addr=0x%0" PRIx64,
-                   getPath(i_target), i_addr);
+        lg2::error(
+            "SCOM read failure: target={SCOM_TARGET} addr={SCOM_ADDRESS}",
+            "SCOM_TARGET", getPath(i_target), "SCOM_ADDRESS",
+            (lg2::hex | lg2::field64), i_addr, "SCOM_ACCESS_RC", rc);
     }
 
     return rc;
@@ -86,8 +89,10 @@
 
     if (0 != rc)
     {
-        trace::err("CFAM read failure: target=%s addr=0x%08x",
-                   getPath(i_target), i_addr);
+        lg2::error(
+            "CFAM read failure: target={CFAM_TARGET} addr={CFAM_ADDRESS}",
+            "CFAM_TARGET", getPath(i_target), "CFAM_ADDRESS",
+            (lg2::hex | lg2::field32), i_addr, "CFAM_ACCESS_RC", rc);
     }
 
     return rc;