Attention handler trace message refactor

Signed-off-by: austinfcui <austinfcui@gmail.com>
Change-Id: If86af8fb88b0ce15f6a626676a412a5cee88acc0
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());
         }
     }