lg2: Support sdbusplus::message::object_path type
Currently the sdbusplus::message::object_path type is not supported.
To print the sdbusplus::message::object_path type, we need to
explicitly obtain the string.
Resolves openbmc/phosphor-logging#25.
Without this patch:
```
sdbusplus::message::object_path objectPath;
info("objectPath: {PATH}", "PATH", objectPath.str);
```
With this patch:
```
sdbusplus::message::object_path objectPath;
info("objectPath: {PATH}", "PATH", objectPath);
```
Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: Ica2eb19554203af578b8368b4c63c0efc9835857
diff --git a/lib/include/phosphor-logging/lg2/conversion.hpp b/lib/include/phosphor-logging/lg2/conversion.hpp
index 87f5936..cdff0a3 100644
--- a/lib/include/phosphor-logging/lg2/conversion.hpp
+++ b/lib/include/phosphor-logging/lg2/conversion.hpp
@@ -58,6 +58,10 @@
template <typename T>
concept exception_type = std::derived_from<std::decay_t<T>, std::exception>;
+template <typename T>
+concept sdbusplus_object_path =
+ std::derived_from<std::decay_t<T>, sdbusplus::message::object_path>;
+
/** Concept listing all of the types we know how to convert into a format
* for logging.
*/
@@ -65,7 +69,8 @@
concept unsupported_log_convert_types =
!(unsigned_integral_except_bool<T> || std::signed_integral<T> ||
std::same_as<bool, T> || std::floating_point<T> || string_like_type<T> ||
- pointer_type<T> || sdbusplus_enum<T> || exception_type<T>);
+ pointer_type<T> || sdbusplus_enum<T> || exception_type<T> ||
+ sdbusplus_object_path<T>);
/** Any type we do not know how to convert for logging gives a nicer
* static_assert message. */
@@ -255,6 +260,26 @@
return std::make_tuple(h, (f | str).value, v.what());
}
+/* Logging conversion for object path. */
+template <log_flags... Fs, sdbusplus_object_path V>
+static auto log_convert(const char* h, log_flag<Fs...> f, V&& v)
+{
+ // Compile-time checks for valid formatting flags.
+ prohibit(f, bin);
+ prohibit(f, dec);
+ prohibit(f, field16);
+ prohibit(f, field32);
+ prohibit(f, field64);
+ prohibit(f, field8);
+ prohibit(f, floating);
+ prohibit(f, hex);
+ prohibit(f, signed_val);
+ prohibit(f, unsigned_val);
+
+ // Treat like a string, but get the 'str' from the object path.
+ return std::make_tuple(h, (f | str).value, v.str);
+}
+
/** Class to facilitate walking through the arguments of the `lg2::log` function
* and ensuring correct parameter types and conversion operations.
*/