shill: add object id to scoped log messages
Add object identifier (DBus::Path) string to scoped logging messages. If
the logging message is called from a static method, SLOG will be called
with nullptr and the log will use (anon) for the object id. Objects
without identifying information will use the (class_name) as their logged
identifier.
BUG=chromium:403996
TEST=ran unit tests and manually inspected net.log
Change-Id: Idf23911a303f5edc4b82917bf1e2cea3f8e44e60
Reviewed-on: https://chromium-review.googlesource.com/224812
Tested-by: Rebecca Silberstein <silberst@chromium.org>
Reviewed-by: Paul Stewart <pstew@chromium.org>
Commit-Queue: Rebecca Silberstein <silberst@chromium.org>
diff --git a/dbus_properties.cc b/dbus_properties.cc
index f7406d7..7f8456c 100644
--- a/dbus_properties.cc
+++ b/dbus_properties.cc
@@ -14,6 +14,10 @@
namespace shill {
+namespace Logging {
+static string ObjectID(DBusProperties *d) { return "(dbus_properties)"; }
+}
+
namespace {
template <typename ValueType>
@@ -24,15 +28,16 @@
DBusPropertiesMap::const_iterator it = properties.find(key);
if (it == properties.end()) {
- SLOG(DBus, 2) << "Key '" << key << "' not found.";
+ SLOG(DBus, nullptr, 2) << "Key '" << key << "' not found.";
return false;
}
string actual_type = it->second.signature();
string expected_type = DBus::type<ValueType>::sig();
if (actual_type != expected_type) {
- SLOG(DBus, 2) << "Key '" << key << "' type mismatch (expected '"
- << expected_type << "', actual '" << actual_type << "').";
+ SLOG(DBus, nullptr, 2) << "Key '" << key << "' type mismatch (expected '"
+ << expected_type << "', actual '" << actual_type
+ << "').";
return false;
}