From 9af7445da295149ff0fd9cb1c27b37143475b1b1 Mon Sep 17 00:00:00 2001 From: badaix Date: Sun, 23 Feb 2020 19:12:27 +0100 Subject: [PATCH] Add log tags --- server/publishZeroConf/publish_avahi.cpp | 24 ++++++++++++---------- server/publishZeroConf/publish_bonjour.cpp | 16 ++++++++------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/server/publishZeroConf/publish_avahi.cpp b/server/publishZeroConf/publish_avahi.cpp index b166ee29..e7123a17 100644 --- a/server/publishZeroConf/publish_avahi.cpp +++ b/server/publishZeroConf/publish_avahi.cpp @@ -23,6 +23,8 @@ #include +static constexpr auto LOG_TAG = "Avahi"; + static AvahiEntryGroup* group; static AvahiSimplePoll* simple_poll; static char* name; @@ -43,7 +45,7 @@ void PublishAvahi::publish(const std::vector& services) if (!(simple_poll = avahi_simple_poll_new())) { /// TODO: error handling - LOG(ERROR) << "Failed to create simple poll object.\n"; + LOG(ERROR, LOG_TAG) << "Failed to create simple poll object.\n"; } /// Allocate a new client @@ -53,7 +55,7 @@ void PublishAvahi::publish(const std::vector& services) /// Check wether creating the client object succeeded if (!client_) { - LOG(ERROR) << "Failed to create client: " << avahi_strerror(error) << "\n"; + LOG(ERROR, LOG_TAG) << "Failed to create client: " << avahi_strerror(error) << "\n"; } poll(); @@ -94,7 +96,7 @@ void PublishAvahi::entry_group_callback(AvahiEntryGroup* g, AvahiEntryGroupState { case AVAHI_ENTRY_GROUP_ESTABLISHED: /// The entry group has been established successfully - LOG(INFO) << "Service '" << name << "' successfully established.\n"; + LOG(INFO, LOG_TAG) << "Service '" << name << "' successfully established.\n"; break; case AVAHI_ENTRY_GROUP_COLLISION: @@ -106,7 +108,7 @@ void PublishAvahi::entry_group_callback(AvahiEntryGroup* g, AvahiEntryGroupState avahi_free(name); name = n; - LOG(NOTICE) << "Service name collision, renaming service to '" << name << "'\n"; + LOG(NOTICE, LOG_TAG) << "Service name collision, renaming service to '" << name << "'\n"; /// And recreate the services static_cast(userdata)->create_services(avahi_entry_group_get_client(g)); @@ -115,7 +117,7 @@ void PublishAvahi::entry_group_callback(AvahiEntryGroup* g, AvahiEntryGroupState case AVAHI_ENTRY_GROUP_FAILURE: - LOG(ERROR) << "Entry group failure: " << avahi_strerror(avahi_client_errno(avahi_entry_group_get_client(g))) << "\n"; + LOG(ERROR, LOG_TAG) << "Entry group failure: " << avahi_strerror(avahi_client_errno(avahi_entry_group_get_client(g))) << "\n"; /// Some kind of failure happened while we were registering our services avahi_simple_poll_quit(simple_poll); @@ -136,7 +138,7 @@ void PublishAvahi::create_services(AvahiClient* c) { if (!(group = avahi_entry_group_new(c, entry_group_callback, this))) { - LOG(ERROR) << "avahi_entry_group_new() failed: " << avahi_strerror(avahi_client_errno(c)) << "\n"; + LOG(ERROR, LOG_TAG) << "avahi_entry_group_new() failed: " << avahi_strerror(avahi_client_errno(c)) << "\n"; goto fail; } } @@ -145,7 +147,7 @@ void PublishAvahi::create_services(AvahiClient* c) int ret; if (avahi_entry_group_is_empty(group)) { - LOG(INFO) << "Adding service '" << name << "'\n"; + LOG(INFO, LOG_TAG) << "Adding service '" << name << "'\n"; /// We will now add two services and one subtype to the entry group for (const auto& service : services_) @@ -156,7 +158,7 @@ void PublishAvahi::create_services(AvahiClient* c) if (ret == AVAHI_ERR_COLLISION) goto collision; - LOG(ERROR) << "Failed to add " << service.name_ << " service: " << avahi_strerror(ret) << "\n"; + LOG(ERROR, LOG_TAG) << "Failed to add " << service.name_ << " service: " << avahi_strerror(ret) << "\n"; goto fail; } } @@ -173,7 +175,7 @@ void PublishAvahi::create_services(AvahiClient* c) /// Tell the server to register the service if ((ret = avahi_entry_group_commit(group)) < 0) { - LOG(ERROR) << "Failed to commit entry group: " << avahi_strerror(ret) << "\n"; + LOG(ERROR, LOG_TAG) << "Failed to commit entry group: " << avahi_strerror(ret) << "\n"; goto fail; } } @@ -187,7 +189,7 @@ collision: avahi_free(name); name = n; - LOG(INFO) << "Service name collision, renaming service to '" << name << "'\n"; + LOG(INFO, LOG_TAG) << "Service name collision, renaming service to '" << name << "'\n"; avahi_entry_group_reset(group); @@ -214,7 +216,7 @@ void PublishAvahi::client_callback(AvahiClient* c, AvahiClientState state, AVAHI case AVAHI_CLIENT_FAILURE: - LOG(ERROR) << "Client failure: " << avahi_strerror(avahi_client_errno(c)) << "\n"; + LOG(ERROR, LOG_TAG) << "Client failure: " << avahi_strerror(avahi_client_errno(c)) << "\n"; avahi_simple_poll_quit(simple_poll); break; diff --git a/server/publishZeroConf/publish_bonjour.cpp b/server/publishZeroConf/publish_bonjour.cpp index 448cab1f..45a106d1 100644 --- a/server/publishZeroConf/publish_bonjour.cpp +++ b/server/publishZeroConf/publish_bonjour.cpp @@ -22,6 +22,8 @@ #include "common/aixlog.hpp" #include "publish_bonjour.hpp" +static constexpr auto LOG_TAG = "Bonjour"; + typedef union { unsigned char b[2]; unsigned short NotAnInteger; @@ -93,7 +95,7 @@ void PublishBonjour::worker() DNSServiceErrorType err = DNSServiceProcessResult(clients[n]); if (err) { - LOG(ERROR) << "DNSServiceProcessResult returned " << err << "\n"; + LOG(ERROR, LOG_TAG) << "DNSServiceProcessResult returned " << err << "\n"; active_ = false; } } @@ -103,7 +105,7 @@ void PublishBonjour::worker() // myTimerCallBack(); else if (result < 0) { - LOG(ERROR) << "select() returned " << result << " errno " << errno << " " << strerror(errno) << "\n"; + LOG(ERROR, LOG_TAG) << "select() returned " << result << " errno " << errno << " " << strerror(errno) << "\n"; if (errno != EINTR) active_ = false; } @@ -120,23 +122,23 @@ static void DNSSD_API reg_reply(DNSServiceRef sdref, const DNSServiceFlags flags PublishBonjour* publishBonjour = (PublishBonjour*)context; (void)publishBonjour; // unused - LOG(INFO) << "Got a reply for service " << name << "." << regtype << domain << "\n"; + LOG(INFO, LOG_TAG) << "Got a reply for service " << name << "." << regtype << domain << "\n"; if (errorCode == kDNSServiceErr_NoError) { if (flags & kDNSServiceFlagsAdd) - LOG(INFO) << "Name now registered and active\n"; + LOG(INFO, LOG_TAG) << "Name now registered and active\n"; else - LOG(INFO) << "Name registration removed\n"; + LOG(INFO, LOG_TAG) << "Name registration removed\n"; } else if (errorCode == kDNSServiceErr_NameConflict) { /// TODO: Error handling - LOG(INFO) << "Name in use, please choose another\n"; + LOG(INFO, LOG_TAG) << "Name in use, please choose another\n"; exit(-1); } else - LOG(INFO) << "Error " << errorCode << "\n"; + LOG(INFO, LOG_TAG) << "Error " << errorCode << "\n"; if (!(flags & kDNSServiceFlagsMoreComing)) fflush(stdout);