xref: /openbmc/phosphor-logging/lib/elog.cpp (revision 6f533669)
1 #include "config.h"
2 
3 #include <phosphor-logging/elog.hpp>
4 
5 #include <stdexcept>
6 
7 namespace phosphor
8 {
9 namespace logging
10 {
11 namespace details
12 {
13 using namespace sdbusplus::server::xyz::openbmc_project::logging;
14 
15 auto _prepareMsg(const char* funcName)
16 {
17     using phosphor::logging::log;
18     constexpr auto IFACE_INTERNAL(
19         "xyz.openbmc_project.Logging.Internal.Manager");
20 
21     // Transaction id is located at the end of the string separated by a period.
22 
23     auto b = sdbusplus::bus::new_default();
24 
25     auto m = b.new_method_call(BUSNAME_LOGGING, OBJ_INTERNAL, IFACE_INTERNAL,
26                                funcName);
27     return m;
28 }
29 
30 uint32_t commit(const char* name)
31 {
32     auto msg = _prepareMsg("Commit");
33     uint64_t id = sdbusplus::server::transaction::get_id();
34     msg.append(id, name);
35     auto bus = sdbusplus::bus::new_default();
36     auto reply = bus.call(msg);
37     uint32_t entryID;
38     reply.read(entryID);
39     return entryID;
40 }
41 
42 uint32_t commit(const char* name, Entry::Level level)
43 {
44     auto msg = _prepareMsg("CommitWithLvl");
45     uint64_t id = sdbusplus::server::transaction::get_id();
46     msg.append(id, name, static_cast<uint32_t>(level));
47     auto bus = sdbusplus::bus::new_default();
48     auto reply = bus.call(msg);
49     uint32_t entryID;
50     reply.read(entryID);
51     return entryID;
52 }
53 } // namespace details
54 
55 uint32_t commit(std::string&& name)
56 {
57     log<level::ERR>("method is deprecated, use commit() with exception type");
58     return phosphor::logging::details::commit(name.c_str());
59 }
60 
61 } // namespace logging
62 } // namespace phosphor
63