diff options
| author | Deepak Kodihalli <dkodihal@in.ibm.com> | 2018-04-03 02:08:42 -0500 |
|---|---|---|
| committer | Deepak Kodihalli <dkodihal@in.ibm.com> | 2018-04-09 08:42:53 -0500 |
| commit | 6fd9dc48615e22d53be7181fb8d122f67695036e (patch) | |
| tree | bc0659aea48ae59f15eb16b6b83345f9c595bed4 /log_manager.cpp | |
| parent | 14a8c8de981933fdb362597d7cf989249846ee9f (diff) | |
| download | phosphor-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 'log_manager.cpp')
| -rw-r--r-- | log_manager.cpp | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/log_manager.cpp b/log_manager.cpp index cc5e187..92454fe 100644 --- a/log_manager.cpp +++ b/log_manager.cpp @@ -25,17 +25,37 @@ namespace logging { namespace internal { -void Manager::commit(uint64_t transactionId, std::string errMsg) + +inline auto getLevel(const std::string& errMsg) { - auto reqLevel = level::ERR; // Default to ERR - auto levelmap = g_errLevelMap.find(errMsg); + auto reqLevel = Entry::Level::Error; // Default to Error + auto levelmap = g_errLevelMap.find(errMsg); if (levelmap != g_errLevelMap.end()) { - reqLevel = levelmap->second; + reqLevel = static_cast<Entry::Level>(levelmap->second); } - if (static_cast<Entry::Level>(reqLevel) < Entry::sevLowerLimit) + return reqLevel; +} + +void Manager::commit(uint64_t transactionId, std::string errMsg) +{ + auto level = getLevel(errMsg); + _commit(transactionId, std::move(errMsg), level); +} + +void Manager::commitWithLvl(uint64_t transactionId, std::string errMsg, + uint32_t errLvl) +{ + _commit(transactionId, std::move(errMsg), + static_cast<Entry::Level>(errLvl)); +} + +void Manager::_commit(uint64_t transactionId, std::string&& errMsg, + Entry::Level errLvl) +{ + if (errLvl < Entry::sevLowerLimit) { if (realErrors.size() >= ERROR_CAP) { @@ -158,7 +178,7 @@ void Manager::commit(uint64_t transactionId, std::string errMsg) // Create error Entry dbus object entryId++; - if (static_cast<Entry::Level>(reqLevel) >= Entry::sevLowerLimit) + if (errLvl >= Entry::sevLowerLimit) { infoErrors.push_back(entryId); } @@ -179,7 +199,7 @@ void Manager::commit(uint64_t transactionId, std::string errMsg) objPath, entryId, ms, // Milliseconds since 1970 - static_cast<Entry::Level>(reqLevel), + errLvl, std::move(errMsg), std::move(additionalData), std::move(objects), |

