Attn: Limit trace length messages

Limit trace length messages specifically for exception messages which
tend to be long.

Signed-off-by: Ben Tyner <ben.tyner@ibm.com>
Change-Id: I50360121541c92b732ffe4502c5084497ebb0357
diff --git a/attn/attn_dbus.cpp b/attn/attn_dbus.cpp
index 8765f43..9f4bbc9 100644
--- a/attn/attn_dbus.cpp
+++ b/attn/attn_dbus.cpp
@@ -63,15 +63,19 @@
         }
         else
         {
-            std::string traceMsg =
-                "dbusMethod service not found: " + i_path + ", " + i_interface;
-            trace<level::INFO>(traceMsg.c_str());
+            // 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());
         }
     }
     catch (const sdbusplus::exception::SdBusError& e)
     {
-        std::string traceMsg = "dbusMethod exception: " + std::string(e.what());
-        trace<level::INFO>(traceMsg.c_str());
+        trace<level::INFO>("dbusMethod exception");
+        std::string traceMsg = std::string(e.what(), maxTraceLen);
+        trace<level::ERROR>(traceMsg.c_str());
     }
 
     return rc;
@@ -114,9 +118,9 @@
         }
         catch (const sdbusplus::exception::SdBusError& e)
         {
-            std::string traceMsg =
-                "createPel exception: " + std::string(e.what());
-            trace<level::INFO>(traceMsg.c_str());
+            trace<level::INFO>("createPel exception");
+            std::string traceMsg = std::string(e.what(), maxTraceLen);
+            trace<level::ERROR>(traceMsg.c_str());
         }
     }
 
@@ -168,9 +172,9 @@
         }
         catch (const sdbusplus::exception::SdBusError& e)
         {
-            std::string traceMsg =
-                "createPelRaw exception: " + std::string(e.what());
-            trace<level::INFO>(traceMsg.c_str());
+            trace<level::INFO>("createPelRaw exception");
+            std::string traceMsg = std::string(e.what(), maxTraceLen);
+            trace<level::ERROR>(traceMsg.c_str());
         }
     }
 }
@@ -208,8 +212,9 @@
         }
         catch (const sdbusplus::exception::SdBusError& e)
         {
-            std::string traceMsg = "getPel exception: " + std::string(e.what());
-            trace<level::INFO>(traceMsg.c_str());
+            trace<level::INFO>("getPel exception");
+            std::string traceMsg = std::string(e.what(), maxTraceLen);
+            trace<level::ERROR>(traceMsg.c_str());
         }
     }
 
diff --git a/attn/attn_logging.cpp b/attn/attn_logging.cpp
index f51bb46..3395c19 100644
--- a/attn/attn_logging.cpp
+++ b/attn/attn_logging.cpp
@@ -152,9 +152,9 @@
         }
         catch (const std::exception& e)
         {
-            std::string traceMessage =
-                "createFFDCTraceFiles: " + std::string(e.what());
-            trace<level::INFO>(traceMessage.c_str());
+            trace<level::INFO>("createFFDCTraceFiles exception");
+            std::string traceMsg = std::string(e.what(), maxTraceLen);
+            trace<level::INFO>(traceMsg.c_str());
         }
     }
 }
diff --git a/attn/attn_logging.hpp b/attn/attn_logging.hpp
index 4f1f785..842f677 100644
--- a/attn/attn_logging.hpp
+++ b/attn/attn_logging.hpp
@@ -10,6 +10,8 @@
 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";
diff --git a/attn/ti_handler.cpp b/attn/ti_handler.cpp
index 9752fca..fc58d49 100644
--- a/attn/ti_handler.cpp
+++ b/attn/ti_handler.cpp
@@ -375,11 +375,11 @@
         reply.read(result);
         autoReboot = std::get<bool>(result);
     }
-    catch (const sdbusplus::exception::SdBusError& ec)
+    catch (const sdbusplus::exception::SdBusError& e)
     {
-        std::string traceMessage =
-            "Error in AutoReboot Get: " + std::string(ec.what());
-        trace<level::INFO>(traceMessage.c_str());
+        trace<level::INFO>("autoRebootEnbabled exception");
+        std::string traceMsg = std::string(e.what(), maxTraceLen);
+        trace<level::ERROR>(traceMsg.c_str());
     }
 
     return autoReboot;