Attention handler trace message refactor

Signed-off-by: austinfcui <austinfcui@gmail.com>
Change-Id: If86af8fb88b0ce15f6a626676a412a5cee88acc0
diff --git a/attn/attn_common.cpp b/attn/attn_common.cpp
index d3bb6ba..ee62961 100644
--- a/attn/attn_common.cpp
+++ b/attn/attn_common.cpp
@@ -5,6 +5,7 @@
 #include <attn/attn_logging.hpp>
 #include <sdbusplus/bus.hpp>
 #include <util/pdbg.hpp>
+#include <util/trace.hpp>
 
 #include <iomanip>
 #include <iostream>
@@ -32,31 +33,23 @@
 
         if ((nullptr != fsiTarget) && (nullptr != pibTarget))
         {
-            // buffer for formatted strings (+1 for null, just in case)
-            char buffer[sizeof("some read error: 0x0123456789ABCDEF ")];
-
             // get first debug reg (CFAM)
             if (RC_SUCCESS != fsi_read(fsiTarget, l_cfamAddr, &l_cfamData))
             {
-                sprintf(buffer, "cfam read error: 0x%08x", l_cfamAddr);
-                trace<level::ERROR>(buffer);
+                trace::err("cfam read error: 0x%08x", l_cfamAddr);
                 l_cfamData = 0xFFFFFFFF;
             }
 
             // Get SCOM regs next (just 2 of them)
             if (RC_SUCCESS != pib_read(pibTarget, l_scomAddr1, &l_scomData1))
             {
-                sprintf(buffer, "scom read error: 0x%016" PRIx64 "",
-                        l_scomAddr1);
-                trace<level::ERROR>(buffer);
+                trace::err("scom read error: 0x%016" PRIx64 "", l_scomAddr1);
                 l_scomData1 = 0xFFFFFFFFFFFFFFFFull;
             }
 
             if (RC_SUCCESS != pib_read(pibTarget, l_scomAddr2, &l_scomData2))
             {
-                sprintf(buffer, "scom read error: 0x%016" PRIx64 "",
-                        l_scomAddr2);
-                trace<level::ERROR>(buffer);
+                trace::err("scom read error: 0x%016" PRIx64 "", l_scomAddr2);
                 l_scomData2 = 0xFFFFFFFFFFFFFFFFull;
             }
         }
@@ -64,26 +57,12 @@
         // Trace out the results here of all 3 regs
         // (Format should resemble FSP: HostBoot Reg:0000283C  Data:AA801504
         // 00000000  Proc:00050001 )
-        std::stringstream ss1, ss2, ss3;
-
-        ss1 << "HostBoot Reg:" << std::setw(8) << std::setfill('0') << std::hex
-            << l_cfamAddr << " Data:" << l_cfamData << " Proc:00000000";
-
-        ss2 << "HostBoot Reg:" << std::setw(8) << std::setfill('0') << std::hex
-            << l_scomAddr1 << " Data:" << std::setw(16) << l_scomData1
-            << " Proc:00000000";
-
-        ss3 << "HostBoot Reg:" << std::setw(8) << std::setfill('0') << std::hex
-            << l_scomAddr2 << " Data:" << std::setw(16) << l_scomData2
-            << " Proc:00000000";
-
-        std::string strobj1 = ss1.str();
-        std::string strobj2 = ss2.str();
-        std::string strobj3 = ss3.str();
-
-        trace<level::INFO>(strobj1.c_str());
-        trace<level::INFO>(strobj2.c_str());
-        trace<level::INFO>(strobj3.c_str());
+        trace::inf("HostBoot Reg:%08x Data:%08x Proc:00000000", l_cfamAddr,
+                   l_cfamData);
+        trace::inf("HostBoot Reg:%08x Data:%016" PRIx64 " Proc:00000000",
+                   l_scomAddr1, l_scomData1);
+        trace::inf("HostBoot Reg:%08x Data:%016" PRIx64 " Proc:00000000",
+                   l_scomAddr2, l_scomData2);
     }
 
     return;
@@ -110,7 +89,7 @@
             // sanity check
             if (nullptr == pibTarget)
             {
-                trace<level::INFO>("pib path or target not found");
+                trace::inf("pib path or target not found");
                 continue;
             }
 
@@ -124,7 +103,7 @@
                 // sanity check
                 if (nullptr == fsiTarget)
                 {
-                    trace<level::INFO>("fsi path or target not found");
+                    trace::inf("fsi path or target not found");
                     continue;
                 }
 
@@ -134,14 +113,14 @@
                 if (RC_SUCCESS != fsi_read(fsiTarget, 0x1007, &isr_val))
                 {
                     // log cfam read error
-                    trace<level::ERROR>("Error! cfam read 0x1007 FAILED");
+                    trace::err("cfam read 0x1007 FAILED");
                     eventAttentionFail((int)AttnSection::attnHandler |
                                        ATTN_PDBG_CFAM);
                 }
                 // check for invalid/stale value
                 else if (0xffffffff == isr_val)
                 {
-                    trace<level::ERROR>("Error! cfam read 0x1007 INVALID");
+                    trace::err("cfam read 0x1007 INVALID");
                     continue;
                 }
                 // check recoverable error status bit
diff --git a/attn/attn_dbus.cpp b/attn/attn_dbus.cpp
index a9af4c6..5b6016f 100644
--- a/attn/attn_dbus.cpp
+++ b/attn/attn_dbus.cpp
@@ -1,6 +1,7 @@
 #include <attn_common.hpp>
 #include <attn_dbus.hpp>
 #include <attn_logging.hpp>
+#include <util/trace.hpp>
 
 #include <string>
 #include <vector>
@@ -66,18 +67,15 @@
         else
         {
             // This trace will be picked up in event log
-            trace<level::INFO>("dbusMethod service not found");
-            std::string traceMsgPath = std::string(i_path, maxTraceLen);
-            trace<level::INFO>(traceMsgPath.c_str());
-            std::string traceMsgIface = std::string(i_interface, maxTraceLen);
-            trace<level::INFO>(traceMsgIface.c_str());
+            trace::inf("dbusMethod service not found");
+            trace::inf(i_path.c_str());
+            trace::inf(i_interface.c_str());
         }
     }
     catch (const sdbusplus::exception::SdBusError& e)
     {
-        trace<level::ERROR>("dbusMethod exception");
-        std::string traceMsg = std::string(e.what(), maxTraceLen);
-        trace<level::ERROR>(traceMsg.c_str());
+        trace::err("dbusMethod exception");
+        trace::err(e.what());
     }
 
     return rc;
@@ -120,9 +118,8 @@
         }
         catch (const sdbusplus::exception::SdBusError& e)
         {
-            trace<level::ERROR>("createPel exception");
-            std::string traceMsg = std::string(e.what(), maxTraceLen);
-            trace<level::ERROR>(traceMsg.c_str());
+            trace::err("createPel exception");
+            trace::err(e.what());
         }
     }
 
@@ -141,11 +138,8 @@
     size_t numBytes = write(fd, i_buffer.data(), i_buffer.size());
     if (i_buffer.size() != numBytes)
     {
-        std::stringstream traceMsg;
-        traceMsg << filePath.c_str() << " only " << (int)numBytes << " of "
-                 << (int)i_buffer.size() << " bytes written";
-        auto strobj = traceMsg.str();
-        trace<level::ERROR>(strobj.c_str());
+        trace::err("%s only %u of %u bytes written", filePath.c_str(), numBytes,
+                   i_buffer.size());
     }
 
     lseek(fd, 0, SEEK_SET);
@@ -174,9 +168,8 @@
         }
         catch (const sdbusplus::exception::SdBusError& e)
         {
-            trace<level::ERROR>("createPelRaw exception");
-            std::string traceMsg = std::string(e.what(), maxTraceLen);
-            trace<level::ERROR>(traceMsg.c_str());
+            trace::err("createPelRaw exception");
+            trace::err(e.what());
         }
     }
 }
@@ -214,9 +207,8 @@
         }
         catch (const sdbusplus::exception::SdBusError& e)
         {
-            trace<level::ERROR>("getPel exception");
-            std::string traceMsg = std::string(e.what(), maxTraceLen);
-            trace<level::ERROR>(traceMsg.c_str());
+            trace::err("getPel exception");
+            trace::err(e.what());
         }
     }
 
diff --git a/attn/attn_dump.cpp b/attn/attn_dump.cpp
index 52bfca0..0c7f427 100644
--- a/attn/attn_dump.cpp
+++ b/attn/attn_dump.cpp
@@ -3,6 +3,7 @@
 #include <attn/attn_logging.hpp>
 #include <sdbusplus/bus.hpp>
 #include <sdbusplus/exception.hpp>
+#include <util/trace.hpp>
 
 namespace attn
 {
@@ -36,8 +37,8 @@
                                     "OperationStatus.InProgress" != *status))
         {
             // dump is done, trace some info and change in progress flag
-            trace<level::INFO>(i_path.c_str());
-            trace<level::INFO>((*status).c_str());
+            trace::inf(i_path.c_str());
+            trace::inf(status->c_str());
             o_inProgress = false;
         }
     }
@@ -68,13 +69,13 @@
             });
 
     // wait for dump status to be completed (complete == true)
-    trace<level::INFO>("dump requested (waiting)");
+    trace::inf("dump requested (waiting)");
     while (true == inProgress)
     {
         bus.wait(0);
         bus.process_discard();
     }
-    trace<level::INFO>("dump completed");
+    trace::inf("dump completed");
 }
 
 /** Request a dump from the dump manager */
@@ -131,9 +132,8 @@
         }
         catch (const sdbusplus::exception::SdBusError& e)
         {
-            trace<level::ERROR>("requestDump exception");
-            std::string traceMsg = std::string(e.what(), maxTraceLen);
-            trace<level::ERROR>(traceMsg.c_str());
+            trace::err("requestDump exception");
+            trace::err(e.what());
         }
     }
 }
diff --git a/attn/attn_handler.cpp b/attn/attn_handler.cpp
index 66eb2fc..79c5e2b 100644
--- a/attn/attn_handler.cpp
+++ b/attn/attn_handler.cpp
@@ -80,7 +80,7 @@
     uint32_t isr_val, isr_mask;
 
     // loop through processors looking for active attentions
-    trace<level::INFO>("Attention handler started");
+    trace::inf("Attention handler started");
 
     pdbg_target* target;
     pdbg_for_each_class_target("proc", target)
@@ -97,7 +97,7 @@
             // sanity check
             if (nullptr == pibTarget)
             {
-                trace<level::INFO>("pib path or target not found");
+                trace::inf("pib path or target not found");
                 continue;
             }
 
@@ -111,13 +111,12 @@
                 // sanity check
                 if (nullptr == fsiTarget)
                 {
-                    trace<level::INFO>("fsi path or target not found");
+                    trace::inf("fsi path or target not found");
                     continue;
                 }
 
                 // trace the proc number
-                std::string traceMsg = "proc: " + std::to_string(proc);
-                trace<level::INFO>(traceMsg.c_str());
+                trace::inf("proc: %u", proc);
 
                 isr_val = 0xffffffff; // invalid isr value
 
@@ -125,23 +124,19 @@
                 if (RC_SUCCESS != fsi_read(fsiTarget, 0x1007, &isr_val))
                 {
                     // log cfam read error
-                    trace<level::INFO>("Error! cfam read 0x1007 FAILED");
+                    trace::err("cfam read 0x1007 FAILED");
                     eventAttentionFail((int)AttnSection::attnHandler |
                                        ATTN_PDBG_CFAM);
                 }
                 else if (0xffffffff == isr_val)
                 {
-                    trace<level::INFO>("Error! cfam read 0x1007 INVALID");
+                    trace::err("cfam read 0x1007 INVALID");
                     continue;
                 }
                 else
                 {
                     // trace isr value
-                    std::stringstream ssIsr;
-                    ssIsr << "cfam 0x1007 = 0x" << std::setw(8)
-                          << std::setfill('0') << std::hex << isr_val;
-                    std::string strobjIsr = ssIsr.str();
-                    trace<level::INFO>(strobjIsr.c_str());
+                    trace::inf("cfam 0x1007 = 0x%08x", isr_val);
 
                     isr_mask = 0xffffffff; // invalid isr mask
 
@@ -149,23 +144,19 @@
                     if (RC_SUCCESS != fsi_read(fsiTarget, 0x100d, &isr_mask))
                     {
                         // log cfam read error
-                        trace<level::INFO>("Error! cfam read 0x100d FAILED");
+                        trace::err("cfam read 0x100d FAILED");
                         eventAttentionFail((int)AttnSection::attnHandler |
                                            ATTN_PDBG_CFAM);
                     }
                     else if (0xffffffff == isr_mask)
                     {
-                        trace<level::INFO>("Error! cfam read 0x100d INVALID");
+                        trace::err("cfam read 0x100d INVALID");
                         continue;
                     }
                     else
                     {
                         // trace true mask
-                        std::stringstream ssMask;
-                        ssMask << "cfam 0x100d = 0x" << std::setw(8)
-                               << std::setfill('0') << std::hex << isr_mask;
-                        std::string strobjMask = ssMask.str();
-                        trace<level::INFO>(strobjMask.c_str());
+                        trace::inf("cfam 0x100d = 0x%08x", isr_mask);
 
                         // SBE vital attention active and not masked?
                         if (true == activeAttn(isr_val, isr_mask, SBE_ATTN))
@@ -233,7 +224,7 @@
 {
     int rc = RC_SUCCESS; // assume checkstop handled
 
-    trace<level::INFO>("checkstop handler started");
+    trace::inf("checkstop handler started");
 
     // capture some additional data for logs/traces
     addHbStatusRegs();
@@ -241,7 +232,7 @@
     // if checkstop handling enabled, handle checkstop attention
     if (false == (i_attention->getConfig()->getFlag(enCheckstop)))
     {
-        trace<level::INFO>("Checkstop handling disabled");
+        trace::inf("Checkstop handling disabled");
     }
     else
     {
@@ -290,7 +281,7 @@
     if (nullptr != attnProc)
     {
 #ifdef CONFIG_PHAL_API
-        trace<level::INFO>("using libphal to get TI info");
+        trace::inf("using libphal to get TI info");
 
         // phal library uses proc target for get ti info
         if (PDBG_TARGET_ENABLED == pdbg_target_probe(attnProc))
@@ -313,7 +304,7 @@
             }
         }
 #else
-        trace<level::INFO>("using libpdbg to get TI info");
+        trace::inf("using libpdbg to get TI info");
 
         // pdbg library uses pib target for get ti info
         char path[16];
@@ -333,7 +324,7 @@
     // dynamic TI info is not available
     if (nullptr == tiInfo)
     {
-        trace<level::INFO>("TI info data ptr is invalid");
+        trace::inf("TI info data ptr is invalid");
         getStaticTiInfo(tiInfo);
         tiInfoStatic = true;
     }
@@ -350,7 +341,7 @@
     }
     else
     {
-        trace<level::INFO>("TI info NOT valid");
+        trace::inf("TI info NOT valid");
 
         // if configured to handle TI as default special attention
         if (i_attention->getConfig()->getFlag(dfltTi))
@@ -387,7 +378,7 @@
     // trace non-successful exit condition
     if (RC_SUCCESS != rc)
     {
-        trace<level::INFO>("Special attn not handled");
+        trace::inf("Special attn not handled");
     }
 
     return rc;
@@ -413,23 +404,23 @@
     // if attention active
     if (0 != (i_val & i_attn))
     {
-        std::stringstream ss;
+        std::string msg;
 
         bool validAttn = true; // known attention type
 
         switch (i_attn)
         {
             case SBE_ATTN:
-                ss << "SBE attn";
+                msg = "SBE attn";
                 break;
             case CHECKSTOP_ATTN:
-                ss << "Checkstop attn";
+                msg = "Checkstop attn";
                 break;
             case SPECIAL_ATTN:
-                ss << "Special attn";
+                msg = "Special attn";
                 break;
             default:
-                ss << "Unknown attn";
+                msg       = "Unknown attn";
                 validAttn = false;
         }
 
@@ -442,12 +433,11 @@
             }
             else
             {
-                ss << " masked";
+                msg += " masked";
             }
         }
 
-        std::string strobj = ss.str();      // ss.str() is temporary
-        trace<level::INFO>(strobj.c_str()); // commit trace stream
+        trace::inf(msg.c_str()); // commit trace stream
     }
 
     return rc;
@@ -522,7 +512,7 @@
     }
 
     // trace host state
-    trace<level::INFO>(stateString.c_str());
+    trace::inf(stateString.c_str());
 }
 
 /**
@@ -540,16 +530,8 @@
     {
         TiDataArea* tiDataArea = (TiDataArea*)tiInfo;
 
-        std::stringstream ss; // string stream object for tracing
-        std::string strobj;   // string object for tracing
-
         // trace a few known TI data area values
-        ss.str(std::string()); // empty the stream
-        ss.clear();            // clear the stream
-        ss << "TI data command = 0x" << std::setw(2) << std::setfill('0')
-           << std::hex << (int)tiDataArea->command;
-        strobj = ss.str();
-        trace<level::INFO>(strobj.c_str());
+        trace::inf("TI data command = 0x02x", tiDataArea->command);
 
         // Another check for valid TI Info since it has been seen that
         // tiInfo[0] != 0 but TI info is not valid
@@ -558,26 +540,12 @@
             tiInfoValid = true;
 
             // trace some more data since TI info appears valid
-            ss.str(std::string()); // empty the stream
-            ss.clear();            // clear the stream
-            ss << "TI data term-type = 0x" << std::setw(2) << std::setfill('0')
-               << std::hex << (int)tiDataArea->hbTerminateType;
-            strobj = ss.str();
-            trace<level::INFO>(strobj.c_str());
+            trace::inf("TI data term-type = 0x02x",
+                       tiDataArea->hbTerminateType);
 
-            ss.str(std::string()); // empty the stream
-            ss.clear();            // clear the stream
-            ss << "TI data SRC format = 0x" << std::setw(2) << std::setfill('0')
-               << std::hex << (int)tiDataArea->srcFormat;
-            strobj = ss.str();
-            trace<level::INFO>(strobj.c_str());
+            trace::inf("TI data SRC format = 0x02x", tiDataArea->srcFormat);
 
-            ss.str(std::string()); // empty the stream
-            ss.clear();            // clear the stream
-            ss << "TI data source = 0x" << std::setw(2) << std::setfill('0')
-               << std::hex << (int)tiDataArea->source;
-            strobj = ss.str();
-            trace<level::INFO>(strobj.c_str());
+            trace::inf("TI data source = 0x02x", tiDataArea->source);
         }
     }
 
diff --git a/attn/attn_logging.cpp b/attn/attn_logging.cpp
index 94a54bd..9de91f2 100644
--- a/attn/attn_logging.cpp
+++ b/attn/attn_logging.cpp
@@ -7,23 +7,11 @@
 #include <attn/attn_logging.hpp>
 #include <attn/pel/pel_minimal.hpp>
 #include <phosphor-logging/log.hpp>
+#include <util/trace.hpp>
 
 namespace attn
 {
 
-/** @brief Journal entry of type INFO using phosphor logging */
-template <>
-void trace<INFO>(const char* i_message)
-{
-    phosphor::logging::log<phosphor::logging::level::INFO>(i_message);
-}
-
-template <>
-void trace<ERROR>(const char* i_message)
-{
-    phosphor::logging::log<phosphor::logging::level::ERR>(i_message);
-}
-
 /** @brief Tuple containing information about ffdc files */
 using FFDCTuple =
     std::tuple<util::FFDCFormat, uint8_t, uint8_t, sdbusplus::message::unix_fd>;
@@ -69,11 +57,8 @@
     size_t numBytes = write(fd, static_cast<char*>(i_buffer), i_size);
     if (i_size != numBytes)
     {
-        std::stringstream traceMsg;
-        traceMsg << file.getPath().c_str() << " only " << (int)numBytes
-                 << " of " << (int)i_size << " bytes written";
-        auto strobj = traceMsg.str();
-        trace<level::ERROR>(strobj.c_str());
+        trace::err("%s only %u of %u bytes written", file.getPath().c_str(),
+                   numBytes, i_size);
     }
 
     lseek(fd, 0, SEEK_SET);
@@ -110,11 +95,8 @@
         size_t numBytes = write(fd, buffer.c_str(), buffer.size());
         if (buffer.size() != numBytes)
         {
-            std::stringstream traceMsg;
-            traceMsg << file.getPath().c_str() << " only " << (int)numBytes
-                     << " of " << (int)buffer.size() << " bytes written";
-            auto strobj = traceMsg.str();
-            trace<level::ERROR>(strobj.c_str());
+            trace::err("%s only %u of %u bytes written", file.getPath().c_str(),
+                       numBytes, buffer.size());
         }
     }
 
@@ -155,9 +137,8 @@
         }
         catch (const std::exception& e)
         {
-            trace<level::INFO>("createFFDCTraceFiles exception");
-            std::string traceMsg = std::string(e.what(), maxTraceLen);
-            trace<level::INFO>(traceMsg.c_str());
+            trace::inf("createFFDCTraceFiles exception");
+            trace::inf(e.what());
         }
     }
 }
@@ -411,11 +392,8 @@
                 size_t numBytes = read(pelFd, buffer.data(), buffer.size());
                 if (buffer.size() != numBytes)
                 {
-                    std::stringstream traceMsg;
-                    traceMsg << "Error reading event log: " << (int)numBytes
-                             << " of " << (int)buffer.size() << " bytes read";
-                    auto strobj = traceMsg.str();
-                    trace<level::ERROR>(strobj.c_str());
+                    trace::err("Error reading event log: %u of %u bytes read",
+                               numBytes, buffer.size());
                 }
                 else
                 {
@@ -479,8 +457,7 @@
         }
     }
 
-    std::string traceMsg = "TI info size = " + std::to_string(tiInfoSize);
-    trace<level::INFO>(traceMsg.c_str());
+    trace::inf("TI info size = %u", tiInfoSize);
 
     event(EventType::Terminate, i_additionalData,
           createFFDCFiles(i_tiInfoData, tiInfoSize));
diff --git a/attn/attn_logging.hpp b/attn/attn_logging.hpp
index f165aaa..efbabf7 100644
--- a/attn/attn_logging.hpp
+++ b/attn/attn_logging.hpp
@@ -10,19 +10,10 @@
 namespace attn
 {
 
-constexpr int maxTraceLen = 64; // characters
-
 constexpr auto pathLogging   = "/xyz/openbmc_project/logging";
 constexpr auto levelPelError = "xyz.openbmc_project.Logging.Entry.Level.Error";
 constexpr auto eventPelTerminate = "xyz.open_power.Attn.Error.Terminate";
 
-/** @brief Logging level types */
-enum level
-{
-    INFO,
-    ERROR
-};
-
 /** @brief Logging event types */
 enum class EventType
 {
@@ -34,13 +25,6 @@
     PhalSbeChipop = 5
 };
 
-/** @brief Maximum length of a single trace event message */
-static const size_t trace_msg_max_len = 255;
-
-/** @brief Create trace message template */
-template <level L>
-void trace(const char* i_message);
-
 /** @brief Commit special attention TI event to log */
 void eventTerminate(std::map<std::string, std::string> i_additionalData,
                     char* i_tiInfoData);
diff --git a/attn/attn_monitor.cpp b/attn/attn_monitor.cpp
index 053d615..96723b2 100644
--- a/attn/attn_monitor.cpp
+++ b/attn/attn_monitor.cpp
@@ -1,6 +1,6 @@
 #include <attn/attn_handler.hpp>
-#include <attn/attn_logging.hpp>
 #include <attn/attn_monitor.hpp>
+#include <util/trace.hpp>
 
 namespace attn
 {
@@ -8,9 +8,6 @@
 /** @brief Register a callback for gpio event */
 void AttnMonitor::scheduleGPIOEvent()
 {
-    //    std::string logMessage = "... waiting for events ...";
-    //    trace<level::INFO>(logMessage.c_str());
-
     // Register async callback, note that callback is a
     // lambda function with "this" pointer captured
     iv_gpioEventDescriptor.async_wait(
@@ -18,13 +15,11 @@
         [this](const boost::system::error_code& ec) {
             if (ec)
             {
-                std::string logMessage =
-                    "GPIO Async wait error: " + std::string(ec.message());
-                trace<level::INFO>(logMessage.c_str());
+                trace::err("GPIO Async wait error: %s", ec.message().c_str());
             }
             else
             {
-                trace<level::INFO>("Attention GPIO active");
+                trace::inf("Attention GPIO active");
                 handleGPIOEvent(); // gpio trigger detected
             }
             return;
@@ -40,8 +35,7 @@
     if (gpiod_line_event_read_fd(iv_gpioEventDescriptor.native_handle(),
                                  &gpioEvent) < 0)
     {
-        logMessage = "GPIO line read failed";
-        trace<level::INFO>(logMessage.c_str());
+        trace::err("GPIO line read failed");
     }
     else
     {
@@ -54,14 +48,12 @@
 
             // gpio == 1, GPIO handler should not be executing
             case 1:
-                logMessage = "GPIO handler out of sync";
-                trace<level::INFO>(logMessage.c_str());
+                trace::inf("GPIO handler out of sync");
                 break;
 
             // unexpected value
             default:
-                logMessage = "GPIO line unexpected value";
-                trace<level::INFO>(logMessage.c_str());
+                trace::inf("GPIO line unexpected value");
         }
     }
     scheduleGPIOEvent(); // continue monitoring gpio
@@ -72,8 +64,7 @@
 {
     if (0 != gpiod_line_request(iv_gpioLine, &iv_gpioConfig, 0))
     {
-        std::string logMessage = "failed request for GPIO";
-        trace<level::INFO>(logMessage.c_str());
+        trace::err("failed request for GPIO");
     }
     else
     {
@@ -82,8 +73,7 @@
         gpioLineFd = gpiod_line_event_get_fd(iv_gpioLine);
         if (gpioLineFd < 0)
         {
-            std::string logMessage = "failed to get file descriptor";
-            trace<level::INFO>(logMessage.c_str());
+            trace::err("failed to get file descriptor");
         }
         else
         {
diff --git a/attn/bp_handler.cpp b/attn/bp_handler.cpp
index 1e36526..3c93bfd 100644
--- a/attn/bp_handler.cpp
+++ b/attn/bp_handler.cpp
@@ -1,6 +1,7 @@
 #include <attn/attn_common.hpp>
 #include <attn/attn_logging.hpp>
 #include <sdbusplus/bus.hpp>
+#include <util/trace.hpp>
 
 namespace attn
 {
@@ -16,7 +17,7 @@
     int rc = RC_SUCCESS; // assume success
 
     // trace message
-    trace<level::INFO>("Notify Cronus");
+    trace::inf("Notify Cronus");
 
     // notify Cronus over dbus
     try
@@ -32,9 +33,8 @@
     }
     catch (const sdbusplus::exception::SdBusError& e)
     {
-        trace<level::INFO>("bpHandler() exception");
-        std::string traceMsg = std::string(e.what(), maxTraceLen);
-        trace<level::ERROR>(traceMsg.c_str());
+        trace::inf("bpHandler() exception");
+        trace::err(e.what());
         rc = RC_NOT_HANDLED;
     }
 
diff --git a/attn/ti_handler.cpp b/attn/ti_handler.cpp
index bdd6f8a..1dffed9 100644
--- a/attn/ti_handler.cpp
+++ b/attn/ti_handler.cpp
@@ -7,6 +7,7 @@
 #include <sdbusplus/bus.hpp>
 #include <sdbusplus/exception.hpp>
 #include <util/dbus.hpp>
+#include <util/trace.hpp>
 
 #include <iomanip>
 #include <iostream>
@@ -69,7 +70,7 @@
  */
 void handlePhypTi(TiDataArea* i_tiDataArea)
 {
-    trace<level::INFO>("PHYP TI");
+    trace::inf("PHYP TI");
 
     // gather additional data for PEL
     std::map<std::string, std::string> tiAdditionalData;
@@ -128,7 +129,7 @@
  */
 void handleHbTiWithEid(TiDataArea* i_tiDataArea)
 {
-    trace<level::INFO>("HB TI with PLID/EID");
+    trace::inf("HB TI with PLID/EID");
 
     if (nullptr != i_tiDataArea)
     {
@@ -156,7 +157,7 @@
  */
 void handleHbTiWithSrc(TiDataArea* i_tiDataArea)
 {
-    trace<level::INFO>("HB TI with SRC");
+    trace::inf("HB TI with SRC");
 
     // handle specific hostboot reason codes
     if (nullptr != i_tiDataArea)
@@ -164,10 +165,7 @@
         // Reason code is byte 2 and 3 of 4 byte srcWord12HbWord0
         uint16_t reasonCode = be32toh(i_tiDataArea->srcWord12HbWord0);
 
-        // buffer for formatted string (+1 for null, just in case)
-        char buffer[sizeof("reason code 1234 ")];
-        sprintf(buffer, "reason code %04x", reasonCode);
-        trace<level::INFO>(buffer);
+        trace::inf("reason code %04x", reasonCode);
 
         // for clean shutdown (reason code 050B) no PEL and no dump
         if (reasonCode != HB_SRC_SHUTDOWN_REQUEST)
@@ -184,6 +182,7 @@
             tiAdditionalData["Subsystem"] = std::to_string(
                 static_cast<uint8_t>(pel::SubsystemID::hostboot));
 
+            // TODO: will update as part of other story.
             // Translate hex src value to ascii. This results in an 8
             // character SRC (hostboot SRC is 32 bits)
             std::stringstream src;
@@ -192,7 +191,7 @@
             tiAdditionalData["SrcAscii"] = src.str();
 
             // dump flag is only valid for TI with EID (not TI with SRC)
-            trace<level::INFO>("Ignoring TI info dump flag for HB TI with SRC");
+            trace::inf("Ignoring TI info dump flag for HB TI with SRC");
             tiAdditionalData["Dump"] = "true";
 
             // Generate event log
@@ -224,7 +223,7 @@
  */
 void handleHbTi(TiDataArea* i_tiDataArea)
 {
-    trace<level::INFO>("HB TI");
+    trace::inf("HB TI");
 
     // handle specific hostboot reason codes
     if (nullptr != i_tiDataArea)
@@ -256,6 +255,7 @@
         return;
     }
 
+    // TODO: will update as part of other story.
     std::stringstream ss;
 
     ss << "0x00 TI Area Valid:" << std::setw(2) << std::setfill('0') << std::hex
@@ -338,6 +338,7 @@
         return;
     }
 
+    // TODO: will update as part of other story.
     std::stringstream ss;
 
     ss << "0x00 TI Area Valid:" << std::setw(2) << std::setfill('0') << std::hex
diff --git a/attn/vital_handler.cpp b/attn/vital_handler.cpp
index 4d4b0ce..ae7aaa0 100644
--- a/attn/vital_handler.cpp
+++ b/attn/vital_handler.cpp
@@ -4,6 +4,7 @@
 #include <attn/attn_logging.hpp>
 #include <sdbusplus/bus.hpp>
 #include <util/dbus.hpp>
+#include <util/trace.hpp>
 
 namespace attn
 {
@@ -19,12 +20,12 @@
 {
     int rc = RC_SUCCESS; // assume vital handled
 
-    trace<level::INFO>("vital handler started");
+    trace::inf("vital handler started");
 
     // if vital handling enabled, handle vital attention
     if (false == (i_attention->getConfig()->getFlag(enVital)))
     {
-        trace<level::INFO>("vital handling disabled");
+        trace::inf("vital handling disabled");
         rc = RC_NOT_HANDLED;
     }
     else