lg2: convert state-manager

This converts the rest of phosphor-state-manager over to the lg2
interface.

Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
Change-Id: I3878ec950b6a2b1ada93544cc021cecf14edfb46
diff --git a/chassis_state_manager.cpp b/chassis_state_manager.cpp
index 2dd57eb..f4e761a 100644
--- a/chassis_state_manager.cpp
+++ b/chassis_state_manager.cpp
@@ -5,11 +5,9 @@
 #include "xyz/openbmc_project/Common/error.hpp"
 #include "xyz/openbmc_project/State/Shutdown/Power/error.hpp"
 
-#include <fmt/format.h>
-
 #include <cereal/archives/json.hpp>
 #include <phosphor-logging/elog-errors.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
 #include <sdbusplus/bus.hpp>
 #include <sdbusplus/exception.hpp>
 #include <sdeventplus/event.hpp>
@@ -25,6 +23,8 @@
 namespace manager
 {
 
+PHOSPHOR_LOG2_USING;
+
 // When you see server:: you know we're referencing our base class
 namespace server = sdbusplus::xyz::openbmc_project::State::server;
 
@@ -61,10 +61,9 @@
             SYSTEMD_SERVICE, SYSTEMD_OBJ_PATH, SYSTEMD_INTERFACE, "Subscribe");
         this->bus.call(method);
     }
-    catch (const sdbusplus::exception::exception& ex)
+    catch (const sdbusplus::exception::exception& e)
     {
-        log<level::ERR>("Failed to subscribe to systemd signals",
-                        entry("ERR=%s", ex.what()));
+        error("Failed to subscribe to systemd signals: {ERROR}", "ERROR", e);
         elog<InternalFailure>();
     }
 
@@ -89,9 +88,7 @@
 
         if (std::get<int>(pgood) == 1)
         {
-            log<level::INFO>("Initial Chassis State will be On",
-                             entry("CHASSIS_CURRENT_POWER_STATE=%s",
-                                   convertForMessage(PowerState::On).c_str()));
+            info("Initial Chassis State will be On");
             server::Chassis::currentPowerState(PowerState::On);
             server::Chassis::requestedPowerTransition(Transition::On);
             return;
@@ -125,15 +122,12 @@
         }
 
         // Only log for unexpected error types.
-        log<level::ERR>("Error performing call to get pgood",
-                        entry("ERROR=%s", e.what()));
+        error("Error performing call to get pgood: {ERROR}", "ERROR", e);
         goto fail;
     }
 
 fail:
-    log<level::INFO>("Initial Chassis State will be Off",
-                     entry("CHASSIS_CURRENT_POWER_STATE=%s",
-                           convertForMessage(PowerState::Off).c_str()));
+    info("Initial Chassis State will be Off");
     server::Chassis::currentPowerState(PowerState::Off);
     server::Chassis::requestedPowerTransition(Transition::Off);
 
@@ -172,7 +166,7 @@
     }
     catch (const sdbusplus::exception::exception& e)
     {
-        log<level::ERR>("Error in GetUnit call", entry("ERROR=%s", e.what()));
+        error("Error in GetUnit call: {ERROR}", "ERROR", e);
         return false;
     }
 
@@ -190,8 +184,7 @@
     }
     catch (const sdbusplus::exception::exception& e)
     {
-        log<level::ERR>("Error in ActiveState Get",
-                        entry("ERROR=%s", e.what()));
+        error("Error in ActiveState Get: {ERROR}", "ERROR", e);
         return false;
     }
 
@@ -216,16 +209,15 @@
     }
     catch (const sdbusplus::exception::exception& e)
     {
-        log<level::ERR>("Error in state change - bad encoding",
-                        entry("ERROR=%s", e.what()),
-                        entry("REPLY_SIG=%s", msg.get_signature()));
+        error("Error in state change - bad encoding: {ERROR} {REPLY_SIG}",
+              "ERROR", e, "REPLY_SIG", msg.get_signature());
         return 0;
     }
 
     if ((newStateUnit == CHASSIS_STATE_POWEROFF_TGT) &&
         (newStateResult == "done") && (!stateActive(CHASSIS_STATE_POWERON_TGT)))
     {
-        log<level::INFO>("Received signal that power OFF is complete");
+        info("Received signal that power OFF is complete");
         this->currentPowerState(server::Chassis::PowerState::Off);
         this->setStateChangeTime();
     }
@@ -233,7 +225,7 @@
              (newStateResult == "done") &&
              (stateActive(CHASSIS_STATE_POWERON_TGT)))
     {
-        log<level::INFO>("Received signal that power ON is complete");
+        info("Received signal that power ON is complete");
         this->currentPowerState(server::Chassis::PowerState::On);
         this->setStateChangeTime();
 
@@ -258,9 +250,8 @@
 Chassis::Transition Chassis::requestedPowerTransition(Transition value)
 {
 
-    log<level::INFO>(fmt::format("Change to Chassis Requested Power State: {}",
-                                 convertForMessage(value))
-                         .c_str());
+    info("Change to Chassis Requested Power State: {REQ_POWER_TRAN}",
+         "REQ_POWER_TRAN", value);
     executeTransition(value);
     return server::Chassis::requestedPowerTransition(value);
 }
@@ -268,9 +259,8 @@
 Chassis::PowerState Chassis::currentPowerState(PowerState value)
 {
     PowerState chassisPowerState;
-    log<level::INFO>(fmt::format("Change to Chassis Power State: {}",
-                                 convertForMessage(value))
-                         .c_str());
+    info("Change to Chassis Power State: {CUR_POWER_STATE}", "CUR_POWER_STATE",
+         value);
 
     chassisPowerState = server::Chassis::currentPowerState(value);
     pohTimer.setEnabled(chassisPowerState == PowerState::On);
@@ -332,7 +322,7 @@
     }
     catch (cereal::Exception& e)
     {
-        log<level::ERR>(e.what());
+        error("deserialize exception: {ERROR}", "ERROR", e);
         fs::remove(path);
         return false;
     }
@@ -357,8 +347,8 @@
     }
     catch (const sdeventplus::SdEventError& e)
     {
-        log<level::ERR>("Error occurred during the sdeventplus loop",
-                        entry("ERROR=%s", e.what()));
+        error("Error occurred during the sdeventplus loop: {ERROR}", "ERROR",
+              e);
         phosphor::logging::commit<InternalFailure>();
     }
 }
@@ -389,7 +379,7 @@
     }
     catch (std::exception& e)
     {
-        log<level::ERR>(e.what());
+        error("deserialize exception: {ERROR}", "ERROR", e);
         fs::remove(path);
     }