blob: 70d1ceda59afc5de3d6d72e68317ab0cfa3965fb [file] [log] [blame]
Deepak Kodihalli827b50f2017-02-24 00:00:08 -06001#include "config.h"
Patrick Venturef18bf832018-10-26 18:14:00 -07002
Saqib Khan2bb15192017-02-13 13:19:55 -06003#include <phosphor-logging/elog.hpp>
Arya K Padman5bc26532024-04-10 06:19:25 -05004#include <phosphor-logging/lg2.hpp>
Patrick Williams2544b412022-10-04 08:41:06 -05005
Deepak Kodihalli6fd9dc42018-04-03 02:08:42 -05006#include <stdexcept>
Adriana Kobylakc20dae82017-02-15 13:44:16 -06007
8namespace phosphor
9{
10namespace logging
11{
Marri Devender Rao7d0a07b2017-04-04 03:43:00 -050012namespace details
Adriana Kobylakc20dae82017-02-15 13:44:16 -060013{
Willy Tu6ddbf692023-09-05 10:54:16 -070014using namespace sdbusplus::server::xyz::openbmc_project::logging;
Deepak Kodihalli6fd9dc42018-04-03 02:08:42 -050015
16auto _prepareMsg(const char* funcName)
Marri Devender Rao7d0a07b2017-04-04 03:43:00 -050017{
18 using phosphor::logging::log;
Patrick Venturef18bf832018-10-26 18:14:00 -070019 constexpr auto IFACE_INTERNAL(
20 "xyz.openbmc_project.Logging.Internal.Manager");
Adriana Kobylak205b1132017-02-06 20:15:29 -060021
22 // Transaction id is located at the end of the string separated by a period.
23
24 auto b = sdbusplus::bus::new_default();
Adriana Kobylak205b1132017-02-06 20:15:29 -060025
Matt Spinler6b300d22020-07-15 13:20:44 -050026 auto m = b.new_method_call(BUSNAME_LOGGING, OBJ_INTERNAL, IFACE_INTERNAL,
27 funcName);
Patrick Venturef18bf832018-10-26 18:14:00 -070028 return m;
Deepak Kodihalli6fd9dc42018-04-03 02:08:42 -050029}
30
Lei YUb50c7052021-01-21 16:02:26 +080031uint32_t commit(const char* name)
Deepak Kodihalli6fd9dc42018-04-03 02:08:42 -050032{
33 auto msg = _prepareMsg("Commit");
Adriana Kobylak205b1132017-02-06 20:15:29 -060034 uint64_t id = sdbusplus::server::transaction::get_id();
Deepak Kodihalli6fd9dc42018-04-03 02:08:42 -050035 msg.append(id, name);
36 auto bus = sdbusplus::bus::new_default();
Lei YUb50c7052021-01-21 16:02:26 +080037 auto reply = bus.call(msg);
38 uint32_t entryID;
39 reply.read(entryID);
40 return entryID;
Deepak Kodihalli6fd9dc42018-04-03 02:08:42 -050041}
42
Lei YUb50c7052021-01-21 16:02:26 +080043uint32_t commit(const char* name, Entry::Level level)
Deepak Kodihalli6fd9dc42018-04-03 02:08:42 -050044{
45 auto msg = _prepareMsg("CommitWithLvl");
46 uint64_t id = sdbusplus::server::transaction::get_id();
47 msg.append(id, name, static_cast<uint32_t>(level));
48 auto bus = sdbusplus::bus::new_default();
Lei YUb50c7052021-01-21 16:02:26 +080049 auto reply = bus.call(msg);
50 uint32_t entryID;
51 reply.read(entryID);
52 return entryID;
Adriana Kobylakc20dae82017-02-15 13:44:16 -060053}
Marri Devender Rao7d0a07b2017-04-04 03:43:00 -050054} // namespace details
55
Lei YUb50c7052021-01-21 16:02:26 +080056uint32_t commit(std::string&& name)
Marri Devender Rao7d0a07b2017-04-04 03:43:00 -050057{
Arya K Padman5bc26532024-04-10 06:19:25 -050058 lg2::error("method is deprecated, use commit() with exception type");
Lei YUb50c7052021-01-21 16:02:26 +080059 return phosphor::logging::details::commit(name.c_str());
Marri Devender Rao7d0a07b2017-04-04 03:43:00 -050060}
Adriana Kobylakc20dae82017-02-15 13:44:16 -060061
62} // namespace logging
63} // namespace phosphor