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/dhcp_provider.cc b/dhcp_provider.cc
index 0f6b4b3..f7b3e67 100644
--- a/dhcp_provider.cc
+++ b/dhcp_provider.cc
@@ -18,6 +18,11 @@
namespace shill {
+namespace Logging {
+static auto kModuleLogScope = ScopeLogger::kDHCP;
+static string ObjectID(DHCPProvider *d) { return "(dhcp_provider)"; }
+}
+
namespace {
base::LazyInstance<DHCPProvider> g_dhcp_provider = LAZY_INSTANCE_INITIALIZER;
} // namespace
@@ -31,11 +36,11 @@
dispatcher_(nullptr),
glib_(nullptr),
metrics_(nullptr) {
- SLOG(DHCP, 2) << __func__;
+ SLOG(this, 2) << __func__;
}
DHCPProvider::~DHCPProvider() {
- SLOG(DHCP, 2) << __func__;
+ SLOG(this, 2) << __func__;
}
DHCPProvider* DHCPProvider::GetInstance() {
@@ -46,7 +51,7 @@
EventDispatcher *dispatcher,
GLib *glib,
Metrics *metrics) {
- SLOG(DHCP, 2) << __func__;
+ SLOG(this, 2) << __func__;
listener_.reset(new DHCPCDListener(proxy_factory_->connection(), this));
glib_ = glib;
control_interface_ = control_interface;
@@ -58,7 +63,7 @@
const string &host_name,
const string &lease_file_suffix,
bool arp_gateway) {
- SLOG(DHCP, 2) << __func__ << " device: " << device_name;
+ SLOG(this, 2) << __func__ << " device: " << device_name;
return new DHCPConfig(control_interface_,
dispatcher_,
this,
@@ -71,7 +76,7 @@
}
DHCPConfigRefPtr DHCPProvider::GetConfig(int pid) {
- SLOG(DHCP, 2) << __func__ << " pid: " << pid;
+ SLOG(this, 2) << __func__ << " pid: " << pid;
PIDConfigMap::const_iterator it = configs_.find(pid);
if (it == configs_.end()) {
return nullptr;
@@ -80,17 +85,17 @@
}
void DHCPProvider::BindPID(int pid, const DHCPConfigRefPtr &config) {
- SLOG(DHCP, 2) << __func__ << " pid: " << pid;
+ SLOG(this, 2) << __func__ << " pid: " << pid;
configs_[pid] = config;
}
void DHCPProvider::UnbindPID(int pid) {
- SLOG(DHCP, 2) << __func__ << " pid: " << pid;
+ SLOG(this, 2) << __func__ << " pid: " << pid;
configs_.erase(pid);
}
void DHCPProvider::DestroyLease(const string &name) {
- SLOG(DHCP, 2) << __func__ << " name: " << name;
+ SLOG(this, 2) << __func__ << " name: " << name;
base::DeleteFile(root_.Append(
base::StringPrintf(kDHCPCDPathFormatLease,
name.c_str())), false);