regulators: Create error log entries

Create error log entries when the following regulator operations fail:
* configuration
* presence detection
* sensor monitoring
* closing I2C devices

Use the recently created error_logging_utils namespace to create error
logs based on caught exceptions.

Signed-off-by: Shawn McCarney <shawnmm@us.ibm.com>
Change-Id: I25824ecfdaa270abbce92b52bdea0602271d926d
diff --git a/phosphor-regulators/test/configuration_tests.cpp b/phosphor-regulators/test/configuration_tests.cpp
index 7db4ac5..47279be 100644
--- a/phosphor-regulators/test/configuration_tests.cpp
+++ b/phosphor-regulators/test/configuration_tests.cpp
@@ -20,6 +20,7 @@
 #include "i2c_interface.hpp"
 #include "i2c_write_byte_action.hpp"
 #include "mock_action.hpp"
+#include "mock_error_logging.hpp"
 #include "mock_journal.hpp"
 #include "mock_services.hpp"
 #include "mocked_i2c_interface.hpp"
@@ -43,6 +44,7 @@
 using namespace phosphor::power::regulators::pmbus_utils;
 
 using ::testing::A;
+using ::testing::Ref;
 using ::testing::Return;
 using ::testing::Throw;
 using ::testing::TypedEq;
@@ -195,8 +197,10 @@
 
     // Test where fails
     {
-        // Create mock services.  Expect logDebug() and logError() to be called.
+        // Create mock services.  Expect logDebug(), logError(), and
+        // logI2CError() to be called.
         MockServices services{};
+        MockErrorLogging& errorLogging = services.getMockErrorLogging();
         MockJournal& journal = services.getMockJournal();
         std::vector<std::string> expectedErrMessagesException{
             "I2CException: Failed to write byte: bus /dev/i2c-1, addr 0x70",
@@ -205,6 +209,10 @@
         EXPECT_CALL(journal, logDebug("Configuring vdd_reg")).Times(1);
         EXPECT_CALL(journal, logError(expectedErrMessagesException)).Times(1);
         EXPECT_CALL(journal, logError("Unable to configure vdd_reg")).Times(1);
+        EXPECT_CALL(errorLogging,
+                    logI2CError(Entry::Level::Warning, Ref(journal),
+                                "/dev/i2c-1", 0x70, 0))
+            .Times(1);
 
         // Create I2CWriteByteAction with register 0x7C and value 0x0A
         std::unique_ptr<I2CWriteByteAction> action =
@@ -392,8 +400,10 @@
 
     // Test where fails
     {
-        // Create mock services.  Expect logDebug() and logError() to be called.
+        // Create mock services.  Expect logDebug(), logError(), and logI2CError
+        // to be called.
         MockServices services{};
+        MockErrorLogging& errorLogging = services.getMockErrorLogging();
         MockJournal& journal = services.getMockJournal();
         std::vector<std::string> expectedErrMessagesException{
             "I2CException: Failed to write byte: bus /dev/i2c-1, addr 0x70",
@@ -402,6 +412,10 @@
         EXPECT_CALL(journal, logDebug("Configuring vio2")).Times(1);
         EXPECT_CALL(journal, logError(expectedErrMessagesException)).Times(1);
         EXPECT_CALL(journal, logError("Unable to configure vio2")).Times(1);
+        EXPECT_CALL(errorLogging,
+                    logI2CError(Entry::Level::Warning, Ref(journal),
+                                "/dev/i2c-1", 0x70, 0))
+            .Times(1);
 
         // Create I2CWriteByteAction with register 0x7C and value 0x0A
         std::unique_ptr<I2CWriteByteAction> action =