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