log-manager: enable non-standard path for local tests
Enable the log-manager to be launched with a path other than
`/var/phosphor-logging` to allow it to be ran on a development system
for test purposes. This required some refactoring throughout as to
how paths were handled.
Tested:
After running tests, `/tmp/phosphor-logging` is populated with
entries. Launching `./builddir/phosphor-log-manager
/tmp/phosphor-logging`, the log-manager will have the entries on
dbus:
```
$ busctl --user tree xyz.openbmc_project.Logging
└─ /xyz
└─ /xyz/openbmc_project
└─ /xyz/openbmc_project/logging
├─ /xyz/openbmc_project/logging/entry
│ ├─ /xyz/openbmc_project/logging/entry/100
│ ├─ /xyz/openbmc_project/logging/entry/101
│ ├─ /xyz/openbmc_project/logging/entry/102
│ ├─ /xyz/openbmc_project/logging/entry/103
```
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I84968edeed0dcf73aaf8bb653060b6d3400b9b7b
diff --git a/log_manager_main.cpp b/log_manager_main.cpp
index 207c93c..fda9119 100644
--- a/log_manager_main.cpp
+++ b/log_manager_main.cpp
@@ -4,6 +4,7 @@
#include "extensions.hpp"
#include "log_manager.hpp"
+#include "paths.hpp"
#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/bus.hpp>
@@ -12,10 +13,16 @@
#include <filesystem>
-int main(int /*argc*/, char* /*argv*/[])
+int main(int argc, char* argv[])
{
PHOSPHOR_LOG2_USING_WITH_FLAGS;
+ if (argc >= 1)
+ {
+ PERSIST_PATH_ROOT = strdup(argv[1]);
+ info("Using temporary {PATH} for logs", "PATH", PERSIST_PATH_ROOT);
+ }
+
auto bus = sdbusplus::bus::new_default();
auto event = sdeventplus::Event::get_default();
bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
@@ -28,7 +35,7 @@
phosphor::logging::Manager mgr(bus, OBJ_LOGGING, iMgr);
// Create a directory to persist errors.
- std::filesystem::create_directories(ERRLOG_PERSIST_PATH);
+ std::filesystem::create_directories(phosphor::logging::paths::error());
// Recreate error d-bus objects from persisted errors.
iMgr.restore();