forked from openbmc/phosphor-logging
-
Notifications
You must be signed in to change notification settings - Fork 0
/
elog.cpp
76 lines (63 loc) · 2.19 KB
/
elog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "config.h"
#include <phosphor-logging/elog.hpp>
#include <stdexcept>
namespace phosphor
{
namespace logging
{
namespace details
{
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";
constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper";
constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper";
constexpr auto IFACE_INTERNAL(
"xyz.openbmc_project.Logging.Internal.Manager");
// Transaction id is located at the end of the string separated by a period.
auto b = sdbusplus::bus::new_default();
auto mapper = b.new_method_call(MAPPER_BUSNAME, MAPPER_PATH,
MAPPER_INTERFACE, "GetObject");
mapper.append(OBJ_INTERNAL, std::vector<std::string>({IFACE_INTERNAL}));
auto mapperResponseMsg = b.call(mapper);
if (mapperResponseMsg.is_method_error())
{
throw std::runtime_error("Error in mapper call");
}
std::map<std::string, std::vector<std::string>> mapperResponse;
mapperResponseMsg.read(mapperResponse);
if (mapperResponse.empty())
{
throw std::runtime_error("Error reading mapper response");
}
const auto& host = mapperResponse.cbegin()->first;
auto m =
b.new_method_call(host.c_str(), OBJ_INTERNAL, IFACE_INTERNAL, 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();
msg.append(id, name, static_cast<uint32_t>(level));
auto bus = sdbusplus::bus::new_default();
bus.call_noreply(msg);
}
} // namespace details
void commit(std::string&& name)
{
log<level::ERR>("method is deprecated, use commit() with exception type");
phosphor::logging::details::commit(name.c_str());
}
} // namespace logging
} // namespace phosphor