summaryrefslogtreecommitdiffstats
path: root/elog.cpp
diff options
context:
space:
mode:
authorDeepak Kodihalli <dkodihal@in.ibm.com>2018-04-03 02:08:42 -0500
committerDeepak Kodihalli <dkodihal@in.ibm.com>2018-04-09 08:42:53 -0500
commit6fd9dc48615e22d53be7181fb8d122f67695036e (patch)
treebc0659aea48ae59f15eb16b6b83345f9c595bed4 /elog.cpp
parent14a8c8de981933fdb362597d7cf989249846ee9f (diff)
downloadphosphor-logging-6fd9dc48615e22d53be7181fb8d122f67695036e.tar.gz
phosphor-logging-6fd9dc48615e22d53be7181fb8d122f67695036e.zip
Implement ability to override default error level
Errors reported by the phosphor-logging app have a default error level, and this level is specified in the error's YAML definition. Enable users of the error's report() API to specify an error level. A user may perceive a different error level for an error scenario, for eg there may be certain host errors (for which we set the level as 'Error') that may just be 'Warnings'. Change-Id: I666a0ddcb099e530c423358a3b1c65f33b0ad01e Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
Diffstat (limited to 'elog.cpp')
-rw-r--r--elog.cpp33
1 files changed, 25 insertions, 8 deletions
diff --git a/elog.cpp b/elog.cpp
index 27dfef5..363553b 100644
--- a/elog.cpp
+++ b/elog.cpp
@@ -1,5 +1,6 @@
#include "config.h"
#include <phosphor-logging/elog.hpp>
+#include <stdexcept>
namespace phosphor
{
@@ -7,7 +8,9 @@ namespace logging
{
namespace details
{
-void commit(const char* name)
+using namespace sdbusplus::xyz::openbmc_project::Logging::server;
+
+auto _prepareMsg(const char* funcName)
{
using phosphor::logging::log;
constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper";
@@ -29,16 +32,14 @@ void commit(const char* name)
auto mapperResponseMsg = b.call(mapper);
if (mapperResponseMsg.is_method_error())
{
- log<level::ERR>("Error in mapper call");
- return;
+ throw std::runtime_error("Error in mapper call");
}
std::map<std::string, std::vector<std::string>> mapperResponse;
mapperResponseMsg.read(mapperResponse);
if (mapperResponse.empty())
{
- log<level::ERR>("Error reading mapper response");
- return;
+ throw std::runtime_error("Error reading mapper response");
}
const auto& host = mapperResponse.cbegin()->first;
@@ -46,10 +47,26 @@ void commit(const char* name)
host.c_str(),
OBJ_INTERNAL,
IFACE_INTERNAL,
- "Commit");
+ funcName);
+ return m;
+}
+
+void commit(const char* name)
+{
+ auto msg = _prepareMsg("Commit");
+ uint64_t id = sdbusplus::server::transaction::get_id();
+ msg.append(id, name);
+ auto bus = sdbusplus::bus::new_default();
+ bus.call_noreply(msg);
+}
+
+void commit(const char* name, Entry::Level level)
+{
+ auto msg = _prepareMsg("CommitWithLvl");
uint64_t id = sdbusplus::server::transaction::get_id();
- m.append(id, name);
- b.call_noreply(m);
+ msg.append(id, name, static_cast<uint32_t>(level));
+ auto bus = sdbusplus::bus::new_default();
+ bus.call_noreply(msg);
}
} // namespace details
OpenPOWER on IntegriCloud